You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a minimal example. First consider a simple C++ class defined in foo.h:
#ifndef foo_h
#definefoo_h1// class to set/get a scalar doubleclassfoo {
private:double x;
public:doubleget_x() {return x;}
voidset_x(double _x) {x = _x; return;}
foo(double _x) {set_x(_x);}
};
#endif
Now let's create an R package exporting the class as an Rcpp module:
options(useFancyQuotes=FALSE) # Rcpp::exposeClass uses dQuotepkg_path<- getwd() # where to create packagepkg_name<-"ModuleLoadTest"# name of packagepkg_dir<- file.path(pkg_path, pkg_name) # package root directory# create package set up to export Rcpp modulesRcpp::Rcpp.package.skeleton(name=pkg_name,
path=pkg_path,
force=TRUE,
example_code=FALSE, module=TRUE)
# remove module sample code
file.remove(list.files(file.path(pkg_dir, c("src", "R")),
full.names=TRUE))
# add foo header file to package (assuming foo.h is in current directory)
file.copy(from="foo.h", to= file.path(pkg_dir, "src", "foo.h"))
Finally to wrap the class into a module. First with the R and C++ classes both named foo, which works as expected:
Rcpp::exposeClass(class="foo",
constructors=list("double"),
fields=character(),
methods= c("get_x", "set_x"),
header='#include "foo.h"',
CppClass="foo",
file= file.path(pkg_dir, "src", "fooModule.cpp"),
Rfile= file.path(pkg_dir, "R", "fooClass.R"))
devtools::install(pkg_dir) # install package# simple unit test for getter/setterbar<-ModuleLoadTest::foo(0) # create object
replicate(n=10, {
x<- rnorm(1)
bar$set_x(x)
bar$get_x() -x
}) # should return an array of zeros
However, when I change class = "foo" to class = "fooR" in the above, and rerun devtools:install (also checked with R CMD install and with CRAN and GitHub versions of Rcpp), I get the following output/error message:
It seems that the problem is entirely with R/fooClass.R. That is, if I set Rfile = FALSE in the above and construct the object with bar <- new("fooR", x), install and test both work fine.
Moreover, a small adjustment to R/fooClass.R seems to overcome the issue (at least, for this particular example). Here is the original content of fooClass.R:
fooR<- setRcppClass("fooR", "foo")
If I switch the second argument from foo to fooR, then devtools::install runs without errors and so does the unit test above (via original bar <- ModuleLoadTest::fooR(0)).
Here is the RsessionInfo() after the first call to devtools::install:
Here is a minimal example. First consider a simple C++ class defined in
foo.h
:Now let's create an R package exporting the class as an Rcpp module:
Finally to wrap the class into a module. First with the R and C++ classes both named
foo
, which works as expected:However, when I change
class = "foo"
toclass = "fooR"
in the above, and rerundevtools:install
(also checked withR CMD install
and with CRAN and GitHub versions of Rcpp), I get the following output/error message:It seems that the problem is entirely with
R/fooClass.R
. That is, if I setRfile = FALSE
in the above and construct the object withbar <- new("fooR", x)
, install and test both work fine.Moreover, a small adjustment to
R/fooClass.R
seems to overcome the issue (at least, for this particular example). Here is the original content offooClass.R
:If I switch the second argument from
foo
tofooR
, thendevtools::install
runs without errors and so does the unit test above (via originalbar <- ModuleLoadTest::fooR(0)
).Here is the R
sessionInfo()
after the first call todevtools::install
:The text was updated successfully, but these errors were encountered: