I have a package that compiles C++ at runtime using sourceCpp and I would
like to use testthat with the package. Its clear that testthat sets up a
non-standard environment and so it is difficult to combine it with
sourceCpp. The first hurdle was include paths not working.
This bit of code in the test_ file seemed to fix that:
ccflags = Sys.getenv("CCFLAGS")
ipath = file.path(getwd(), "inst", "include")
ccflags = if (nzchar(ccflags)) paste(ccflags, paste0("-I", ipath)) else
paste0("-I", ipath)
Sys.setenv(CCFLAGS = ccflags)
However, once compiled, the object does not load correctly as I cannot call
the compiled function. Does anyone have a workaround? (I have searched and
not found anything terribly useful.)
THK
http://www.keittlab.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170125/3f545759/attachment.html>
[Rcpp-devel] testthat + sourceCpp
3 messages · JJ Allaire, Tim Keitt
Not 100% sure about this but I think the workaround for using sourceCpp within tests is to define R_TESTS="" (that's what we do in Rcpp and RcppParallel). Here's the code I'm thinking of: https://github.com/RcppCore/Rcpp/blob/master/tests/doRUnit.R#L42-L43 Note that we use RUnit in both of those packages so there could indeed be some issue with testthat that we're not aware of.
On Wed, Jan 25, 2017 at 2:33 PM, Tim Keitt <tkeitt at utexas.edu> wrote:
I have a package that compiles C++ at runtime using sourceCpp and I would
like to use testthat with the package. Its clear that testthat sets up a
non-standard environment and so it is difficult to combine it with
sourceCpp. The first hurdle was include paths not working.
This bit of code in the test_ file seemed to fix that:
ccflags = Sys.getenv("CCFLAGS")
ipath = file.path(getwd(), "inst", "include")
ccflags = if (nzchar(ccflags)) paste(ccflags, paste0("-I", ipath)) else
paste0("-I", ipath)
Sys.setenv(CCFLAGS = ccflags)
However, once compiled, the object does not load correctly as I cannot
call the compiled function. Does anyone have a workaround? (I have searched
and not found anything terribly useful.)
THK
http://www.keittlab.org/
_______________________________________________ Rcpp-devel mailing list Rcpp-devel at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170125/8f33704d/attachment.html>
Figured it out.
My snippet below does _not_ solve the problem of include paths. The key is
to symlink ./inst/include to ./include. After that it works if I call
"devtools::tests()". It fails however with "devtools::check(args =
c('--as-cran'))".
THK
http://www.keittlab.org/
On Wed, Jan 25, 2017 at 5:52 PM, JJ Allaire <jj.allaire at gmail.com> wrote:
Not 100% sure about this but I think the workaround for using sourceCpp within tests is to define R_TESTS="" (that's what we do in Rcpp and RcppParallel). Here's the code I'm thinking of: https://github.com/ RcppCore/Rcpp/blob/master/tests/doRUnit.R#L42-L43 Note that we use RUnit in both of those packages so there could indeed be some issue with testthat that we're not aware of. On Wed, Jan 25, 2017 at 2:33 PM, Tim Keitt <tkeitt at utexas.edu> wrote:
I have a package that compiles C++ at runtime using sourceCpp and I would
like to use testthat with the package. Its clear that testthat sets up a
non-standard environment and so it is difficult to combine it with
sourceCpp. The first hurdle was include paths not working.
This bit of code in the test_ file seemed to fix that:
ccflags = Sys.getenv("CCFLAGS")
ipath = file.path(getwd(), "inst", "include")
ccflags = if (nzchar(ccflags)) paste(ccflags, paste0("-I", ipath)) else
paste0("-I", ipath)
Sys.setenv(CCFLAGS = ccflags)
However, once compiled, the object does not load correctly as I cannot
call the compiled function. Does anyone have a workaround? (I have searched
and not found anything terribly useful.)
THK
http://www.keittlab.org/
_______________________________________________ Rcpp-devel mailing list Rcpp-devel at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170125/d667e095/attachment.html>