[Rcpp-devel] xts inputs and outputs for Rcpp translation

Hideyoshi Maeda hideyoshi.maeda at gmail.com
Thu Feb 6 13:51:20 CET 2014


Hello I am new to Rcpp, and am looking to translate some for loops in R to C++ using Rcpp, but I am sort of stuck at the first hurdle, as the simple tutorials do not really seem to deal with xts structures.

The closest I found for some help online was found here (http://gallery.rcpp.org/articles/accessing-xts-api/) but that seems to only give xts outputs rather than taking in xts inputs. Below is a mock example of R code that has a function and takes an xts object as an input and gives an xts object as an output.

toy.xts <- function(xtsobj,val.vec){
  xtsobj1 <- xtsobj
  for(i in 1:nrow(xtsobj1)){
    if((i %/% 3)==3 ){
      xtsobj1[i,"B"] <- val.vec[1]
    } else {
      xtsobj1[i,c("C","D")] <- val.vec+1
    }
  }
  xtsobj1
}

tmp.xts <- xts(matrix(c(1:500),ncol=5),Sys.Date()-c(1:100))
colnames(tmp.xts) <- LETTERS[1:5]
tmp.vec <- c(0.4,0.9)
toy.xts(tmp.xts,tmp.vec)

I know that this isn’t exactly the use case for converting R code, to C++, but I’m not too sure where to start when dealing with these different/non-simple structures as inputs. Apologies if this is very simple. 

Would the RcppXts packages help at all? It doesn’t seem to have a huge number of functions, and am not too sure how to use it?

Thanks in advance

HLM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140206/435dee1a/attachment.html>


More information about the Rcpp-devel mailing list