Ilya Esteban
Ilya Esteban

Reputation: 95

Can Rcpp package DLLs be unloaded without restarting R?

When installing a Rcpp package on Windows, you need to ensure that the package DLL is unloaded or you get a "Permission Denied" error when copying the new DLL. This means restarting R on every recompile, which is pretty annoying. Is there any way to unload the package DLL without killing R?

I've tried the detach("package:my_package", force=TRUE) command, but it doesnt unload the DLL.

Upvotes: 5

Views: 1126

Answers (3)

hadley
hadley

Reputation: 103918

If you want to do this in your main R session (without using RStudio, which makes reinstalling the package and reloading R very easy), you can use devtools:

library(devtools)
load_all("path/to/my/package")

Among other things, load_all will reload all your R code, and re-compile and reattach the DLL.

Upvotes: 5

Dirk is no longer here
Dirk is no longer here

Reputation: 368301

Opinions are divided on this. I often prefer to run the builds and test outside of my main R session(s), simply by chaining R CMD INSTALL with Rscript (or, on Linux, r calls from littler) to test the new build. If you use proper options to R CMD INSTALL ... to skip parts that may take extra time you get a quick turnaround AND are assured that you do get a fresh build.

And if you want the same behaviour by clicking a button, RStudio offers it too.

Upvotes: 8

wush978
wush978

Reputation: 3174

I guess you need to run library.dynam.unload to unload DLLs.

Upvotes: 5

Related Questions