Skip to content

packages that use modules with classes don't work unless Rcpp is attached #168

Description

@s-u

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions