Packages that use Rcpp modules which expose C++ classes work only if Rcpp is explicitly present on the search path. This has been described, but mis-identified in #118.
To replicate, create a skeleton package via Rcpp::Rcpp.package.skeleton(module=TRUE), build, install and run:
> library(anRpackage)
Warning message:
class "C++Object" is defined (with package slot ‘Rcpp’) but no metadata object found to revise subclass information---not exported? Making a copy in package ‘anRpackage’
> World$new()
Error in .Object$initialize(...) :
could not find function "cpp_object_initializer"
Note that the skeleton uses Imports: Rcpp which is crucial here. If Rcpp is explicitly attached, it works:
> library(Rcpp)
> library(anRpackage)
> World$new()
C++ object <0x1136d40> of class 'World' <0xa6c8b0>
This turns out to be a major problem for the following reason: A package can try to work around this problem by using Depends: Rcpp, but that only applies if the package is also attached itself. This means that the "I don't work if not attached" property becomes contagious in that it bubbles through the package dependency chain - if a package has ever even one ancestor in the dependency chain that is a package with Rcpp module then it itself becomes unusable unless Rcpp attached - so in theory all packages must depend on Rcpp - whether they use it or not. Even if desirable ;), it's not practical, unfortunately.
Packages that use Rcpp modules which expose C++ classes work only if Rcpp is explicitly present on the search path. This has been described, but mis-identified in #118.
To replicate, create a skeleton package via
Rcpp::Rcpp.package.skeleton(module=TRUE), build, install and run:Note that the skeleton uses
Imports: Rcppwhich is crucial here. IfRcppis explicitly attached, it works:This turns out to be a major problem for the following reason: A package can try to work around this problem by using
Depends: Rcpp, but that only applies if the package is also attached itself. This means that the "I don't work if not attached" property becomes contagious in that it bubbles through the package dependency chain - if a package has ever even one ancestor in the dependency chain that is a package with Rcpp module then it itself becomes unusable unless Rcpp attached - so in theory all packages must depend on Rcpp - whether they use it or not. Even if desirable ;), it's not practical, unfortunately.