diff --git a/DESCRIPTION b/DESCRIPTION index 33c1b92d..d411c456 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,6 +13,7 @@ Authors@R: c( person("Laurent", "Berge", role = "ctb"), person("Kevin", "Tappe", role = "ctb"), person("Alina", "Cherkas", role = "ctb"), + person("Ivan", "Krylov", role = "ctb"), person("R Core Team and contributors worldwide", role = "ctb"), person("Martyn", "Plummer", role = "cph"), person("1999-2016 The R Core Team", role = "cph") diff --git a/src/collapse_c.h b/src/collapse_c.h index 76e4c62c..ac239015 100644 --- a/src/collapse_c.h +++ b/src/collapse_c.h @@ -23,6 +23,10 @@ #undef ISNAN #define ISNAN(x) ((x) != (x)) +#ifndef ANY_ATTRIB +#define ANY_ATTRIB(x) (ATTTR(x) != R_NilValue) +#endif + // Initialized in data.table_init.c extern int max_threads; extern SEXP sym_label; diff --git a/src/ffirst.c b/src/ffirst.c index 2336b6a0..655f1e58 100644 --- a/src/ffirst.c +++ b/src/ffirst.c @@ -59,7 +59,7 @@ SEXP ffirst_impl(SEXP x, int ng, SEXP g, int narm, int *gl) { default: error("Unsupported SEXP type!"); } } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, out); if(!isNull(getAttrib(x, R_NamesSymbol))) namesgets(out, ScalarString(STRING_ELT(getAttrib(x, R_NamesSymbol), j))); @@ -171,7 +171,7 @@ SEXP ffirst_impl(SEXP x, int ng, SEXP g, int narm, int *gl) { default: error("Unsupported SEXP type!"); } } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, out); // SHALLOW_DUPLICATE_ATTRIB(out, x); UNPROTECT(1); return out; diff --git a/src/flast.c b/src/flast.c index c49a57b8..79832f82 100644 --- a/src/flast.c +++ b/src/flast.c @@ -51,7 +51,7 @@ SEXP flast_impl(SEXP x, int ng, SEXP g, int narm, int *gl) { default: error("Unsupported SEXP type!"); } } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, out); if(!isNull(getAttrib(x, R_NamesSymbol))) namesgets(out, ScalarString(STRING_ELT(getAttrib(x, R_NamesSymbol), j))); @@ -152,7 +152,7 @@ SEXP flast_impl(SEXP x, int ng, SEXP g, int narm, int *gl) { default: error("Unsupported SEXP type!"); } } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, out); UNPROTECT(1); return out; diff --git a/src/fmean.c b/src/fmean.c index 60853499..d828aaca 100644 --- a/src/fmean.c +++ b/src/fmean.c @@ -274,7 +274,7 @@ SEXP fmeanC(SEXP x, SEXP Rng, SEXP g, SEXP gs, SEXP w, SEXP Rnarm, SEXP Rnthread fmean_weights_omp_impl(px, pw, narm, l, nthreads); } else fmean_weights_g_impl(REAL(out), px, ng, INTEGER(g), pw, narm, l); } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, out); // For example "Units" objects... UNPROTECT(nprotect); return out; @@ -444,7 +444,7 @@ SEXP fmean_g_impl(SEXP x, const int ng, const int *pg, const int *pgs, int narm) default: error("Unsupported SEXP type: '%s'", type2char(TYPEOF(x))); } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); UNPROTECT(1); return res; } @@ -475,7 +475,7 @@ SEXP fmean_wg_impl(SEXP x, const int ng, const int *pg, double *pw, int narm) { SEXP res = PROTECT(allocVector(REALSXP, ng)); fmean_weights_g_impl(REAL(res), REAL(x), ng, pg, pw, narm, l); - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); UNPROTECT(nprotect); return res; } @@ -536,7 +536,7 @@ SEXP fmeanlC(SEXP x, SEXP Rng, SEXP g, SEXP gs, SEXP w, SEXP Rnarm, SEXP Rdrop, // Needed because including it in an OpenMP loop together with ScalarReal() is not thread safe for(int j = 0; j < l; ++j) { SEXP xj = px[j]; - if(ATTRIB(xj) != R_NilValue && !(isObject(xj) && inherits(xj, "ts"))) + if(ANY_ATTRIB(xj) && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, pout[j]); } } else { @@ -560,7 +560,7 @@ SEXP fmeanlC(SEXP x, SEXP Rng, SEXP g, SEXP gs, SEXP w, SEXP Rnarm, SEXP Rdrop, for(int j = 0; j != l; ++j) { SEXP xj = px[j], outj; SET_VECTOR_ELT(out, j, outj = allocVector(REALSXP, ng)); - if(ATTRIB(xj) != R_NilValue && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, outj); + if(ANY_ATTRIB(xj) && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, outj); } #pragma omp parallel for num_threads(nthreads) for(int j = 0; j < l; ++j) fmean_g_omp_impl(px[j], DPTR(pout[j]), ng, pg, pgs, narm); @@ -574,7 +574,7 @@ SEXP fmeanlC(SEXP x, SEXP Rng, SEXP g, SEXP gs, SEXP w, SEXP Rnarm, SEXP Rdrop, for(int j = 0, dup = 0; j != l; ++j) { SEXP xj = px[j], outj; SET_VECTOR_ELT(out, j, outj = allocVector(REALSXP, ng)); - if(ATTRIB(xj) != R_NilValue && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, outj); + if(ANY_ATTRIB(xj) && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, outj); if(TYPEOF(xj) != REALSXP) { if(TYPEOF(xj) != INTSXP && TYPEOF(xj) != LGLSXP) error("Unsupported SEXP type: '%s'", type2char(TYPEOF(xj))); if(dup == 0) {x = PROTECT(shallow_duplicate(x)); ++nprotect; dup = 1;} diff --git a/src/fmin_fmax.c b/src/fmin_fmax.c index 51d0b85f..dd3b9727 100644 --- a/src/fmin_fmax.c +++ b/src/fmin_fmax.c @@ -160,7 +160,7 @@ SEXP fminC(SEXP x, SEXP Rng, SEXP g, SEXP Rnarm) { break; default: error("Unsupported SEXP type"); } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, out); UNPROTECT(1); return out; @@ -234,7 +234,7 @@ SEXP fmaxC(SEXP x, SEXP Rng, SEXP g, SEXP Rnarm) { break; default: error("Unsupported SEXP type"); } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, out); UNPROTECT(1); return out; diff --git a/src/fnth_fmedian_fquantile.c b/src/fnth_fmedian_fquantile.c index cad4cbf9..e039b78a 100644 --- a/src/fnth_fmedian_fquantile.c +++ b/src/fnth_fmedian_fquantile.c @@ -819,7 +819,7 @@ SEXP nth_impl_plain(SEXP x, int narm, int ret, double Q) { SEXP nth_impl(SEXP x, int narm, int ret, double Q) { if(length(x) <= 1) return x; - if(ATTRIB(x) == R_NilValue || (isObject(x) && inherits(x, "ts"))) + if(!ANY_ATTRIB(x) || (isObject(x) && inherits(x, "ts"))) return nth_impl_plain(x, narm, ret, Q); SEXP res = PROTECT(nth_impl_plain(x, narm, ret, Q)); copyMostAttrib(x, res); @@ -878,7 +878,7 @@ SEXP nth_ord_impl(SEXP x, int *pxo, int narm, int ret, double Q) { default: error("Not Supported SEXP Type: '%s'", type2char(TYPEOF(x))); } - if(ATTRIB(x) == R_NilValue || (isObject(x) && inherits(x, "ts"))) return res; + if(!ANY_ATTRIB(x) || (isObject(x) && inherits(x, "ts"))) return res; PROTECT(res); // Needed ?? copyMostAttrib(x, res); UNPROTECT(1); @@ -901,7 +901,7 @@ SEXP w_nth_ord_impl_plain(SEXP x, int *pxo, double *pw, int narm, int ret, doubl // Expects pointer pw to be decremented by 1 SEXP w_nth_ord_impl(SEXP x, int *pxo, double *pw, int narm, int ret, double Q, double h) { if(length(x) <= 1) return x; - if(ATTRIB(x) == R_NilValue || (isObject(x) && inherits(x, "ts"))) + if(!ANY_ATTRIB(x) || (isObject(x) && inherits(x, "ts"))) return w_nth_ord_impl_plain(x, pxo, pw, narm, ret, Q, h); SEXP res = PROTECT(w_nth_ord_impl_plain(x, pxo, pw, narm, ret, Q, h)); copyMostAttrib(x, res); @@ -970,7 +970,7 @@ SEXP nth_g_impl(SEXP x, int ng, int *pgs, int *po, int *pst, int sorted, int nar } } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); UNPROTECT(1); return res; } @@ -1013,7 +1013,7 @@ SEXP nth_g_impl_noalloc(SEXP x, int ng, int *pgs, int *po, int *pst, int sorted, } } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); UNPROTECT(1); return res; } @@ -1045,7 +1045,7 @@ SEXP nth_g_ord_impl(SEXP x, int ng, int *pgs, int *po, int *pst, int narm, int r default: error("Not Supported SEXP Type: '%s'", type2char(TYPEOF(x))); } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); UNPROTECT(1); return res; } @@ -1077,7 +1077,7 @@ SEXP w_nth_g_ord_impl(SEXP x, double *pw, int ng, int *pgs, int *po, int *pst, i default: error("Not Supported SEXP Type: '%s'", type2char(TYPEOF(x))); } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); UNPROTECT(1); return res; } @@ -1130,7 +1130,7 @@ SEXP w_nth_g_qsort_impl(SEXP x, double *pw, int ng, int *pgs, int *po, int *pst, } } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); UNPROTECT(1); return res; } @@ -1397,7 +1397,7 @@ SEXP fnthlC(SEXP x, SEXP p, SEXP g, SEXP w, SEXP Rnarm, SEXP Rdrop, SEXP Rret, S // Needed because including it in an OpenMP loop together with ScalarReal() is not thread safe for(int j = 0; j != l; ++j) { SEXP xj = px[j]; - if(ATTRIB(xj) != R_NilValue && !(isObject(xj) && inherits(xj, "ts"))) + if(ANY_ATTRIB(xj) && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, pout[j]); } diff --git a/src/fprod.c b/src/fprod.c index 8b8f76d1..b5af4892 100644 --- a/src/fprod.c +++ b/src/fprod.c @@ -155,7 +155,7 @@ SEXP fprodC(SEXP x, SEXP Rng, SEXP g, SEXP w, SEXP Rnarm) { } else px = REAL(x); fprod_weights_impl(REAL(out), px, ng, INTEGER(g), pw, narm, l); } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, out); // For example "Units" objects... UNPROTECT(nprotect); return out; diff --git a/src/fsum.c b/src/fsum.c index 16a625d1..68e0114f 100644 --- a/src/fsum.c +++ b/src/fsum.c @@ -354,7 +354,7 @@ SEXP fsumC(SEXP x, SEXP Rng, SEXP g, SEXP w, SEXP Rnarm, SEXP fill, SEXP Rnthrea fsum_weights_omp_impl(px, pw, narm, l, nthreads); } else fsum_weights_g_impl(REAL(out), px, ng, INTEGER(g), pw, narm, l); } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, out); // For example "Units" objects... UNPROTECT(nprotect); return out; @@ -502,7 +502,7 @@ SEXP fsum_impl_SEXP(SEXP x, int narm, int nthreads) { return ScalarReal(fsum_impl_dbl(x, narm, nthreads)); // This is not thread safe... need to do separate serial loop // SEXP res = ScalarReal(fsum_impl_dbl(x, narm, nthreads)); - // if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) { + // if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) { // PROTECT(res); // copyMostAttrib(x, res); // UNPROTECT(1); @@ -529,7 +529,7 @@ SEXP fsum_w_impl_SEXP(SEXP x, double *pw, int narm, int nthreads) { return ScalarReal(fsum_w_impl_dbl(x, pw, narm, nthreads)); // This is not thread safe... need to do separate serial loop // SEXP res = ScalarReal(fsum_w_impl_dbl(x, pw, narm, nthreads)); - // if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) { + // if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) { // PROTECT(res); // copyMostAttrib(x, res); // UNPROTECT(1); @@ -557,7 +557,7 @@ SEXP fsum_g_impl(SEXP x, const int ng, const int *pg, int narm) { default: error("Unsupported SEXP type: '%s'", type2char(TYPEOF(x))); } - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); UNPROTECT(1); return res; } @@ -587,7 +587,7 @@ SEXP fsum_wg_impl(SEXP x, const int ng, const int *pg, double *pw, int narm) { SEXP res = PROTECT(allocVector(REALSXP, ng)); fsum_weights_g_impl(REAL(res), REAL(x), ng, pg, pw, narm, l); - if(ATTRIB(x) != R_NilValue && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); + if(ANY_ATTRIB(x) && !(isObject(x) && inherits(x, "ts"))) copyMostAttrib(x, res); UNPROTECT(nprotect); return res; } @@ -650,7 +650,7 @@ SEXP fsumlC(SEXP x, SEXP Rng, SEXP g, SEXP w, SEXP Rnarm, SEXP fill, SEXP Rdrop, // Needed because including it in an OpenMP loop together with ScalarReal() is not thread safe for(int j = 0; j < l; ++j) { SEXP xj = px[j]; - if(ATTRIB(xj) != R_NilValue && !(isObject(xj) && inherits(xj, "ts"))) + if(ANY_ATTRIB(xj) && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, pout[j]); } } else { @@ -663,7 +663,7 @@ SEXP fsumlC(SEXP x, SEXP Rng, SEXP g, SEXP w, SEXP Rnarm, SEXP fill, SEXP Rdrop, for(int j = 0; j != l; ++j) { SEXP xj = px[j], outj; SET_VECTOR_ELT(out, j, outj = allocVector(TYPEOF(px[j]) == REALSXP ? REALSXP : INTSXP, ng)); - if(ATTRIB(xj) != R_NilValue && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, outj); + if(ANY_ATTRIB(xj) && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, outj); } #pragma omp parallel for num_threads(nthreads) for(int j = 0; j < l; ++j) fsum_g_omp_impl(px[j], DPTR(pout[j]), ng, pg, narm); @@ -677,7 +677,7 @@ SEXP fsumlC(SEXP x, SEXP Rng, SEXP g, SEXP w, SEXP Rnarm, SEXP fill, SEXP Rdrop, for(int j = 0, dup = 0; j != l; ++j) { SEXP xj = px[j], outj; SET_VECTOR_ELT(out, j, outj = allocVector(REALSXP, ng)); - if(ATTRIB(xj) != R_NilValue && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, outj); + if(ANY_ATTRIB(xj) && !(isObject(xj) && inherits(xj, "ts"))) copyMostAttrib(xj, outj); if(TYPEOF(xj) != REALSXP) { if(TYPEOF(xj) != INTSXP && TYPEOF(xj) != LGLSXP) error("Unsupported SEXP type: '%s'", type2char(TYPEOF(xj))); if(dup == 0) {x = PROTECT(shallow_duplicate(x)); ++nprotect; dup = 1;} diff --git a/src/fvar_fsd.cpp b/src/fvar_fsd.cpp index 0bc5a5bd..1d23702a 100644 --- a/src/fvar_fsd.cpp +++ b/src/fvar_fsd.cpp @@ -1,6 +1,10 @@ #include using namespace Rcpp; +#ifndef ANY_ATTRIB +#define ANY_ATTRIB(x) (ATTRIB(x) != R_NilValue) +#endif + // Note: More comments are in fvar.cpp (C++ folder, not on GitHub) // [[Rcpp::export]] @@ -42,7 +46,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& if(sd) M2 = sqrt(M2); if(std::isnan(M2)) M2 = NA_REAL; } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) { + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) { SEXP out = Rf_ScalarReal(M2); Rf_copyMostAttrib(x, out); return out; @@ -82,7 +86,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& } } } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) Rf_copyMostAttrib(x, M2); return M2; } else { @@ -117,7 +121,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& } } } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) Rf_copyMostAttrib(x, M2); return M2; } @@ -160,7 +164,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& if(sd) M2 = sqrt(M2); if(std::isnan(M2)) M2 = NA_REAL; } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) { + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) { SEXP out = Rf_ScalarReal(M2); Rf_copyMostAttrib(x, out); return out; @@ -202,7 +206,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& } } } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) Rf_copyMostAttrib(x, M2); return M2; } else { @@ -239,7 +243,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& } } } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) Rf_copyMostAttrib(x, M2); return M2; } @@ -280,7 +284,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& if(sd) sq_sum = sqrt(sq_sum); if(std::isnan(sq_sum)) sq_sum = NA_REAL; } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) { + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) { SEXP out = Rf_ScalarReal((double)sq_sum); Rf_copyMostAttrib(x, out); return out; @@ -315,7 +319,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& if(std::isnan(sq_sum[i])) sq_sum[i] = NA_REAL; } } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) Rf_copyMostAttrib(x, sq_sum); return sq_sum; } else { @@ -367,7 +371,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& if(std::isnan(sq_sum[i])) sq_sum[i] = NA_REAL; } } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) Rf_copyMostAttrib(x, sq_sum); return sq_sum; } @@ -407,7 +411,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& if(sd) sq_sum = sqrt(sq_sum); if(std::isnan(sq_sum)) sq_sum = NA_REAL; } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) { + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) { SEXP out = Rf_ScalarReal((double)sq_sum); Rf_copyMostAttrib(x, out); return out; @@ -442,7 +446,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& if(std::isnan(sq_sum[i])) sq_sum[i] = NA_REAL; } } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) Rf_copyMostAttrib(x, sq_sum); return sq_sum; } else { @@ -473,7 +477,7 @@ NumericVector fvarsdCpp(const NumericVector& x, int ng = 0, const IntegerVector& if(std::isnan(sq_sum[i])) sq_sum[i] = NA_REAL; } } - if(ATTRIB(x) != R_NilValue && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) + if(ANY_ATTRIB(x) && !(Rf_isObject(x) && Rf_inherits(x, "ts"))) Rf_copyMostAttrib(x, sq_sum); return sq_sum; } diff --git a/src/gsplit.c b/src/gsplit.c index 30563e8a..a57b96a7 100644 --- a/src/gsplit.c +++ b/src/gsplit.c @@ -19,7 +19,7 @@ SEXP gsplit(SEXP x, SEXP gobj, SEXP toint) { } else { // Allocate split vectors and copy attributes and object bits SEXP x1 = PROTECT(allocVector(tx, 1)); copyMostAttrib(x, x1); - SEXP ax = ATTRIB(x1); + SEXP ax = ATTTR(x1); if(length(ax) == 1 && TAG(ax) == sym_label) ax = R_NilValue; int ox = OOBJ(x); // FAZIT: Need to use SET_VECTOR_ELT!! pres[i] = allocVector() doesn't work!! @@ -27,7 +27,7 @@ SEXP gsplit(SEXP x, SEXP gobj, SEXP toint) { for(int i = 0; i != ng; ++i) { // , s4o = IS_S4_OBJECT(x) SEXP resi; SET_VECTOR_ELT(res, i, resi = allocVector(tx, pgs[i])); - SET_ATTRIB(resi, ax); + SET_ATTTR(resi, ax); SET_OOBJ(resi, ox); // if(s4o) SET_S4_OBJECT(resi); } @@ -35,7 +35,7 @@ SEXP gsplit(SEXP x, SEXP gobj, SEXP toint) { for(int i = 0; i != ng; ++i) { SEXP resi; SET_VECTOR_ELT(res, i, resi = allocVector(tx, pgs[i])); // SET_ATTRIB(pres[i] = allocVector(tx, pgs[i]), ax); - SET_ATTRIB(resi, ax); + SET_ATTTR(resi, ax); } } else if(ox != 0) { // Is this even possible? Object bits but no attributes? for(int i = 0; i != ng; ++i) { // , s4o = IS_S4_OBJECT(x) diff --git a/src/handle_attributes.c b/src/handle_attributes.c index 85c9afeb..152054e9 100644 --- a/src/handle_attributes.c +++ b/src/handle_attributes.c @@ -6,13 +6,13 @@ SEXP setAttributes(SEXP x, SEXP a) { - SET_ATTRIB(x, coerceVector(a, LISTSXP)); + SET_ATTTR(x, coerceVector(a, LISTSXP)); classgets(x, getAttrib(x, R_ClassSymbol)); // forcing class after attribute copy !! return x; } SEXP setattributes(SEXP x, SEXP a) { - SET_ATTRIB(x, coerceVector(a, LISTSXP)); + SET_ATTTR(x, coerceVector(a, LISTSXP)); // SET_OOBJ(x, TYPEOF(x)); // if(OOBJ(a)) // This does not work with ts-matrices! could also make compatible with S4 objects ! classgets(x, getAttrib(x, R_ClassSymbol)); return R_NilValue; @@ -81,13 +81,13 @@ SEXP copyMostAttributes(SEXP x, SEXP y) { SEXP CsetAttrib(SEXP object, SEXP a) { if(TYPEOF(object) == VECSXP) { SEXP res = PROTECT(shallow_duplicate(object)); - SET_ATTRIB(res, coerceVector(a, LISTSXP)); + SET_ATTTR(res, coerceVector(a, LISTSXP)); classgets(res, getAttrib(res, R_ClassSymbol)); UNPROTECT(1); return res; } SEXP res = object; - SET_ATTRIB(res, coerceVector(a, LISTSXP)); + SET_ATTTR(res, coerceVector(a, LISTSXP)); classgets(res, getAttrib(res, R_ClassSymbol)); return res; }