I have a function that extracts the index from an
xts
SEXP
I’d like to create a pointer to it so that i can increment it with a condition.
I am able to do this via a deep copy of the index, however dirk’s advice on extracting indices from an xts was to prefer the
SEXP
I can see that there’s no such thing as
s.begin()
SEXP
Rccp-candy
This works:
cppFunction("double xtsIndex_deepPoint(NumericMatrix X) { DatetimeVector v = clone(NumericVector(X.attr("index"))); double * pv = v.begin(); pv++; return *pv; } ") require(xts) xx <- xts(1:10, order.by = seq.Date(Sys.Date(), by = "day", length.out = 10)) R> as.Date(xtsIndex_deepPoint(xx) %/% 86400) == index(xx)[2] [1] TRUE
However, the below does not …
cppFunction("double xtsIndex_point(NumericMatrix X) { SEXP s = X.attr("index"); double * ps = s.begin(); ps++; return *ps; } ") file4c783ed8.cpp: In function 'double xtsIndex_point(Rcpp::NumericMatrix)': file4c783ed8.cpp:8:33: error: request for member 'begin' in 's', which is of pointer type 'SEXP' {aka 'SEXPREC*'} (maybe you meant to use '->' ?) double * ps = s.begin(); ^~~~~ make: *** [C:/PROGRA~1/R/R-40~1.5/etc/x64/Makeconf:229: file4c783ed8.o] Error 1 Error in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir, : Error 1 occurred building shared library.
Anonymous Asked question May 13, 2021
Recent Comments