Error when building R package using roxygen2

☆樱花仙子☆ 提交于 2019-11-30 13:52:34

You're mixing up two things (which are easy to mix up, unfortunately):

First, the // [[Rcpp::export]] attribute is used for auto-generating wrapper functions in two files, RcppExports.cpp and RcppExports.R. A wrapper R function, CPPF, will be auto-generated by Rcpp::compileAttributes() here, and placed into R/RcppExports.R.

Second, roxygen comments can be used to manage the NAMESPACE, e.g. with the @export tag. Note that this is different from // [[Rcpp::export]]!

The auto-generated function is not automatically exported. The Rcpp.package.skeleton() will generate a NAMESPACE file that automatically exports all functions of a given name; ie, the exportPattern("^[[:alpha:]]+") entry. This is good enough for small packages; but as your package gets more complicated you will want more fine-grained control over your namespace. Or you can just adopt a convention where all internal, non-exported functions begin with a .. Either way, this mechanism is what allows the auto-generated function to be exported to your package namespace.

If you want to use roxygen to manage the NAMESPACE, you need to add roxygen comments to your C++ functions if you want them to be exported in the namespace. So you could modify your function as the following:

#include <Rcpp.h>
using namespace Rcpp;

//' @export
// [[Rcpp::export]]
int CPPF(int k){return ++k;}

Note that you might have to run roxygen2::upgradeRoxygen() to ensure that roxygen2 takes over the NAMESPACE, for new versions of roxygen2.

So if 2. does not work, file it as a (reproducible) bug report with the roxygen2 team.

I see no Rcpp issue; it is possible that something went wrong with the Imports: / NAMESPACE declaration. I see no Rcpp issue here (as 1. works fine).

FWIW I also use roxygen2 on some packages, and I too build them from time to time in RStudio.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!