[英]changing R packages' exportPattern to hide Rcpp functions
I'm writing an R package using Rcpp functions. 我正在使用Rcpp函数编写R包。 I need some Rcpp functions to be called within R code, but not to be seen by the final used.
我需要在R代码中调用一些Rcpp函数,但最终使用时不会看到它们。 I am using devtools infrastructure to facilitate the developing process.
我正在使用devtools基础设施来促进开发过程。 Before using Rcpp I used to hide R fuctions intended as "internals" by the "."
在使用Rcpp之前,我习惯用“。”隐藏作为“内部”的R功能。 prexif before the name.
prexif在名字之前。 Therefore the exportPattern("^[[:alpha:]]+") was enough.
因此exportPattern(“^ [[:alpha:]] +”)就足够了。 I have used a "Cpp" suffix on all Rcpp C++ functions.
我在所有Rcpp C ++函数上都使用了“Cpp”后缀。 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.
在我的包中,最终用户不打算使用它们,但是所有这些都需要由导出到最终使用的R函数使用。 I have put // [[Rcpp::export]] before their definition and I replaced exportPattern with export( all function needed to be exported separated by comma).
我把// [[Rcpp :: export]]放在他们的定义之前,我用export导出了exportPattern(需要用逗号分隔所有导出的函数)。 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 "."
但是我有一个包含大量要导出的函数的包,因此我想知道是否可以重写“^ [[:alpha:]] +”以便不导出以“。”开头的所有函数。 or ending with "Cpp".
或以“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 .). 最后,我发现我只需要在Rcpp :: export附近附加一个括号,并命名该函数,因为我希望在R中看到它(也以。开头)。 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 将在R中看作.mult3sum
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.