简体   繁体   中英

Relative file path for Rcpp::sourceCpp

How can I call Rcpp::sourceCpp with a relative path to a C++ file rather than an absolute path? R CMD check and testthat both work when I call Rcpp:sourceCpp with an absolute path:

Rcpp::sourceCpp("/home/jeff/MiniMiniMaxUQ/src/MiniMiniMaxUQ.cpp")

But when I try using system.path or a relative path like

Rcpp::sourceCpp("../src/MiniMiniMaxUQ.cpp")

my package doesn't pass R CMD check because the C++ source file isn't found. It seems like there must be a standard way to do this kind of thing, but I don't know it. I'd greatly appreciate some help.

Why are you using sourceCpp here for a .cpp file already in src/ ? Why not explicitly use .Call to call the compiled code (which will be available for your tests)?

If you really want to dynamically call sourceCpp you can look at the test infrastructure in Rcpp : https://github.com/RcppCore/Rcpp/tree/master/inst/unitTests

The .cpp files in the cpp/ are Rcpp::sourceCpp ed, and the exposed functions are used to run the tests in the runit.* files.

But note that these are separate .cpp files (ie, they're in the inst/ subdirectory, not the src/ folder)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM