Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rcpp::exposeClass doesn't work with differentclass andCppClass arguments #879

Closed
@mlysy

Description

@mlysy

Here is a minimal example. First consider a simple C++ class defined infoo.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 anR 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 codefile.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 theR and C++ classes both namedfoo, 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 objectreplicate(n=10, {x<- rnorm(1)bar$set_x(x)bar$get_x()-x})# should return an array of zeros

However, when I changeclass = "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:

InstallingModuleLoadTest'/Library/Frameworks/R.framework/Resources/bin/R'--no-site-file--no-environ  \--no-save--no-restore--quietCMDINSTALL  \'/Users/mlysy/Documents/R/test/class/ModuleLoadTest'  \--library='/Users/mlysy/Documents/data/R/library'--install-tests*installing*source*packageModuleLoadTest...**libs/usr/local/opt/llvm/bin/clang++-archx86_64-ftemplate-depth-256-I"/Library/Frameworks/R.framework/Resources/include"-DNDEBUG-I"/Users/mlysy/Documents/data/R/library/Rcpp/include"-I/usr/local/include-fPIC-I/usr/local/opt/llvm/include-O3-ffast-math-mtune=native-march=native-Wno-unused-variable-Wno-unused-function-Wno-pragmas-cfooModule.cpp-ofooModule.o/usr/local/opt/llvm/bin/clang++-archx86_64-ftemplate-depth-256-dynamiclib-Wl,-headerpad_max_install_names-undefineddynamic_lookup-single_module-multiply_definedsuppress-L/Library/Frameworks/R.framework/Resources/lib-L/usr/local/opt/llvm/lib-oModuleLoadTest.sofooModule.o-F/Library/Frameworks/R.framework/..-frameworkR-Wl,-framework-Wl,CoreFoundationinstallingto/Users/mlysy/Documents/data/R/library/ModuleLoadTest/libs**R**byte-compileandpreparepackageforlazyloading**help***installinghelpindices**buildingpackageindices**testingifinstalledpackagecanbeloadedError:packageornamespaceloadfailedforModuleLoadTestin .doLoadActions(where,attach):errorinloadaction.__A__.1forpackageModuleLoadTest:Rcpp::loadRcppClass(Class="fooR",CppClass="foo",where=NS):Noobject"foo"inmodule"class_fooR"Error:loadingfailedExecutionhaltedERROR:loadingfailed*removing/Users/mlysy/Documents/data/R/library/ModuleLoadTest*restoringprevious/Users/mlysy/Documents/data/R/library/ModuleLoadTestError:Command failed (1)

It seems that the problem is entirely withR/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 toR/fooClass.R seems to overcome the issue (at least, for this particular example). Here is the original content offooClass.R:

fooR<- setRcppClass("fooR","foo")

If I switch the second argument fromfoo tofooR, thendevtools::install runs without errors and so does the unit test above (via originalbar <- ModuleLoadTest::fooR(0)).

Here is theRsessionInfo() after the first call todevtools::install:

Rversion3.5.0 (2018-04-23)Platform:x86_64-apple-darwin15.6.0 (64-bit)Runningunder:macOSHighSierra10.13.3Matrixproducts:defaultBLAS:/Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylibLAPACK:/Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dyliblocale:[1]en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8attachedbasepackages:[1]statsgraphicsgrDevicesutilsdatasetsmethodsbaseloadedviaa namespace (andnotattached):[1]compiler_3.5.0tools_3.5.0withr_2.1.2memoise_1.1.0  [5]Rcpp_0.12.17pkgKitten_0.1.4git2r_0.21.0digest_0.6.15  [9]devtools_1.13.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp