Greetings, I am trying to create some unit tests for a Rcpp::sourceCpp call. It includes some dependencies with the // [[Rcpp::depends]] flag and compiles and passes if I call the test file with testthat::test_file. However, if I try to call it with devtools::test() to run all of my tests, the compilation will fail. I have discovered that this is because of the way it is trying to find the relevant headers. The correct call should be: g++ -std=gnu++11 -I"C:/Users/mydir/DOCUME~1/R/R-34~1.0/include" -DNDEBUG -I"C:/Users/mydir/Documents/R/R-3.4.0/library/Rcpp/include" -I"C:/Users/mydir/Documents/R/R-3.4.0/library/BH/include" -I"C:/Users/mydir/Documents/R/R-3.4.0/library/RcppEigen/include" -I"C:/Users/mydir/Documents/R/R-3.4.0/library/RViennaCL/include" - *I"C:/Users/mydir/Documents/R/R-3.4.0/library/gpuR/include"* -I"C:/Users/mydir/AppData/Local/Temp/Rtmp4MX4Mi" -I"d:/Compiler/gcc-4.9.3/local330/include" -O2 -Wall -mtune=core2 -c file32503f79470f.cpp -o file32503f79470f.o but instead it is looking locally within the package for the 'include' directory g++ -std=gnu++11 -I"C:/Users/mydir/DOCUME~1/R/R-34~1.0/include" -DNDEBUG -I"C:/Users/mydir/Documents/R/R-3.4.0/library/Rcpp/include" -I"C:/Users/mydir/Documents/R/R-3.4.0/library/BH/include" -I"C:/Users/mydir/Documents/R/R-3.4.0/library/RcppEigen/include" -I"C:/Users/mydir/Documents/R/R-3.4.0/library/RViennaCL/include" - *I"C:/Users/mydir/Documents/R_projects/gpuR/include"* -I"C:/Users/mydir/AppData/Local/Temp/Rtmp4MX4Mi" -I"d:/Compiler/gcc-4.9.3/local330/include" -O2 -Wall -mtune=core2 -c file32503f79470f.cpp -o file32503f79470f.o This directory is within the 'inst' directory and therefore not found when an internal header file is referenced. Any thoughts both why this is different when call the 'devtools::test()' versus calling the individual 'testthat::test_file()'? Regards, Charles
[R-pkg-devel] Testthat environment using sourceCpp
2 messages · Charles Determan, Dirk Eddelbuettel
Charles, I cannot help you with testthat or devtools, but the very issue of how to get C++ test files compiled (with the help of Rcpp) and used is deployed in a number of packages, both ours and other. To take but one example, RcppArmadillo does it with about half a dozen C++ files it keeps in a subdirectory inst/unitTests/cpp/ --- and those files are then sourced and compiled from the test setup function of each unit test file requiring C++. This generally calls a short helper function passing the filename; that helper figures our whether to find the file in the installed or tested package. You can see that helper function here: https://github.com/RcppCore/RcppArmadillo/blob/master/R/unit.test.R I would assume that someone may have cooked up something similar for use with testthat, and presumably also with devtools. Otherwise maybe you can, and then blog about it. We had this setup working pretty much before those tools existed so I never had a reason to switch. Dirk
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org