Search code examples
rrcppdevtoolsr-packagetestthat

Avoid regenerating RcppExports when using devtools::test


I'm maintaining a legacy codebase and am forced to use some dirty hack to get around some game-breaking issues. The hack requires me to manually edit the RcppExports files. Yeah, this sounds stupid, but it works and I'm not going to change the interface very often anyway, so it sticks.

I test my package with devtools::test, which calls testthat::test_dir under the hood, which in turn calls devtools::load_all to "simulate what happens when a package is installed and loaded with library()". This somehow causes my handcrafted RcppExports files to be wiped out and replaced by some autogenerated stuff, leading to a lot of errors.

So I'm here, looking for another hack to fix the issue caused by a hack. Any suggestions?


Solution

  • Very well, as commented. Rcpp attributes are those matching // [[...]], that's what compileAttributes looks for to decide which files to wtite/overwrite. However, that whole mechanism is optional (though recommended). If you have to switch to manual adjustments anyway, then you can remove the attributes and rename the previously generated exports. That way Rcpp will stop treating that code as something it created, so it will stop updating/overwriting it.