Thursday, July 24, 2014

A few things learned about R and Rcpp

Written down here for future reference:


  • Order of functions is important for R reference class, setRefClass should come first, and initialize should come last. This is especially important when you split your code into multiple files. I will list the file structure of my rbed package’s R directory here as an demonstration. You see I have prefixed my R files with numbers to assure the loading order is correct:

  •     R
        ├── 1Rbed_class.R
        ├── 2Rbed_utils.R
        ├── 3Rbed_bedmat.R
        ├── 4Rbed_init.R
        └── RcppExports.R
    
        0 directories, 5 files
                
  • Rcpp is not very smart at typedefs, if you define a shorthand for a very long type, it will complain that the type is unknown, so, never use typedefs with Rcpp / RcppArmadillo. (But things may get better in the future, since these are being actively developed.)

  • If your c++ function isn’t available in R, check if you have added a // [[Rcpp::export]] line right above you function definition.


0 comments: