[Rcpp-devel] Trouble with package unit test and sourceCpp()

Christian Gunning xian at unm.edu
Wed Sep 3 04:42:41 CEST 2014


Dear all,

I'm working on a package that includes a unit test that calls
sourceCpp() to test a particular use-case.  As in [1], test(".") works
swimmingly, but check() and vanilla "R CMD check" fail with the
ominous error "cannot open file 'startup.Rs': No such file or
directory".  If I understand correctly, Dirk and Hadley agree [1] that
this is R's fault,  apparently through the nested "R CMD" calls [1,
2].  Indeed, sourceCpp() includes calls to both "R CMD" and setwd(),
while cppFunction() and evalCpp() both call sourceCpp().

I realize that calling sourceCpp() in a package isn't exactly
standard.  The tested use-case is allowing a package user to easily
write custom C++ functions via sourceCpp("userfile.cpp").  These
functions are then passed to a class method and used internally by
dereferencing and evaluating the XPtr. I've provided a working example
of "userfile.cpp" that a user can copy and extend. Consequently, I
would like some way to test the full process of
write-compile-pass-call.

My question is whether there's a sane workaround, or if I should give
up on these tests. Alternately, is there a cleaner way for a user to
supply hand-written C++ functions?  Using sourceCpp() allows the user
to locally manage custom functions without building a package, and
ensures that user edits aren't overwritten by a package upgrade.

I'm happy to poke, but I'm not sure where to go from here.
Thanks again,
Christian

Refs:
[1] https://github.com/hadley/testthat/issues/144
[2] https://github.com/hadley/devtools/blob/master/R/R.r


More information about the Rcpp-devel mailing list