简体   繁体   中英

changing R packages' exportPattern to hide Rcpp functions

I'm writing an R package using Rcpp functions. I need some Rcpp functions to be called within R code, but not to be seen by the final used. I am using devtools infrastructure to facilitate the developing process. Before using Rcpp I used to hide R fuctions intended as "internals" by the "." prexif before the name. Therefore the exportPattern("^[[:alpha:]]+") was enough. I have used a "Cpp" suffix on all Rcpp C++ functions. In my package none of them are intended to be used by the final user but all of them need to be used by R functions exported to the final used. I have put // [[Rcpp::export]] before their definition and I replaced exportPattern with export( all function needed to be exported separated by comma). But I have a package with a huge list of function to be exported therefore I would like to know if is it possible to rewrite "^[[:alpha:]]+" in order to not export all function beginning with "." or ending with "Cpp".

Finally, I found that I needed just to attach a bracket near to Rcpp::export and naming the function as I want to be seen in R (also beginning with .). For example

// [[Rcpp::export(.mult3sum)]]
double mult3sum(NumericVector x, NumericVector y, NumericVector z)
{
 double total=0;
 int n = x.size();
  for(int i = 0; i < n; ++i) {
   total += x[i]*y[i]*z[i];
  }
 return total;
}

will be seen in R as .mult3sum

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM