daj
daj

Reputation: 7183

RCpp : how to reload recompiled C++ code without restarting R

I'm experimenting with the rcpp_hello_world example generated by Rcpp.package.skeleton().

I made a small change to rcpp_hello_world.cpp, I would like to recompile the package and run the function with the modified code.

However, in spite of clearing the namespace with rm(), detaching the library with detach(), removing the package with remove.packages(), re-compiling and re-installing the package with install.packages(.., repos=NULL, type = 'source'), and reattaching the library with library(), R still runs the old version of the .cpp code.

If I quit and restart R, library() will load the modified .cpp code and run it as intended, but I don't want to have to restart R everytime I make a change to the C++ code (if possible).

How can I get R to properly refresh the C++ call without quitting R?

Upvotes: 3

Views: 954

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368301

It is generally advisable to restart the session / reload the package.

As you may not want to restart your main session, you can

  • use Rscript or littler to load the new example and tests, I often do that

  • use RStudio where the package build process now builds the package and reloads it in a fresh session for you

  • use a system where you can have several R sessions and restart those

Upvotes: 3

Related Questions