Tips About Rcpp
Posted on Oct 09, 2013 in Programming
Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives.
** Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives. **
-
The trick of using a macro
NORCPPto indicate whether you are using the code in Rcpp. This makes it easier to using the code both natively and in Rcpp and makes it easier to debug the code. You have to use the option-D NORCPPwhen compiling the code natively usingg++/clang++. -
The Armadillo package is more conveinient to use than
NumericVector,NumericMarix, etc. when using Rcpp. -
Rcpp doesn't have a uniform integer generator curently, someone is working on sample equivalence currently. You can use
runifto achive what you want. -
I think you misunderstood
Rcpp::sugar, I think vectorized version functions returnNumericVector, it is just that they can be silently convertedarma::rowvecand so on ... -
Rcpp make vectorized version of random number generation functions, however these with prefix
Rf_is non-vectorized. They are functions coming fromRmath.h. -
It is suggested that you alwasy prefixed functions with their namespaces when using Rcpp. Without prefixed namespaces, function name conflictions happen a lot (e.g.,
std::absandRcpp::abs) And when this happens, it is very tricky and very hard to debug. -
RNGScopeeasy to forget, the default seed no randomization at all if you do not use it ... so it is the first to check if you find some thing wrong with your randomization code. -
Rcpp does not have bool equivalent. Use integers (0 and 1) instead.
-
It seems that type is not a big deal for Rcpp, because
as<type>takes care of it. If you pass an object which is not exactly the required type, Rcpp tries cast it to the right type. -
One way to avoid terminating R becuase of DLL problem by Rcpp is to remove all related object every time you restart R. Or if there is a better way to check this?
-
but you should check source code of
rnormin Rcpp to see what they used ...Rf_pnormnot defined either Rcpp, don't use functions with same names as r functions, potentially C functions, confliction ...Rf_qbeta, parameters can be inferred from R documentation problem ofRf_qnorm? not definied? what the heck