[R] How to unload a dll loaded via library.dynam()?

Gábor Csárdi csardi at rmki.kfki.hu
Fri Feb 20 01:43:27 CET 2009

Hmmm, I think restarting R is not a very good solution. It is rather
ugly in the first place. But perhaps even more importantly, it can be
rather inconvenient if one has a large data set in the memory and
needs to save/load it just to reload a package that was updated in the

This happens to me quite often with 20-40Gb of data, so I would really
love to have a solution for proper detach/unload.


On Fri, Feb 20, 2009 at 1:32 AM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> On 19/02/2009 6:19 PM, Alex F. Bokov wrote:
>> Hello. To save the hassle of quitting and restarting R every time I
>> rebuild the package I'm working on (for the purposes of this question called
>> "roots") I would like to write a script cleanly remove the package from my R
>> session and then load it again. Of course detach("package:roots") works for
>> the native R objects in the package. However, the compiled C library remains
>> loaded. Using library.dynam.unload as documented results in:
>> Error in library.dynam.unload("roots.so",
>> "~/R/x86_64-pc-linux-gnu-library/2.8/roots/libs/") :
>>  shared library 'roots' was not loaded
>> I also tried the above command with the file extension omitted and the
>> last one and two levels of the directory path omitted. In both cases I still
>> get the "not loaded" error. I've also Googled the list archives and while
>> there were several questions like mine, none of them were answered by the
>> list. Am I to believe that this is something hardly anybody does? Does this
>> mean everybody sits around waiting for R to start up everytime they make a
>> minor change to the C source?
>> If there is a tutorial for doing this, I'd much appreciate the link.
> This is more of an R-devel question than R-help, so if this doesn't answer
> your question, please follow up there.
> On Windows, the following sort of works:
>> library(rgl)
>> .dynLibs()
>                                           Filename Dynamic.Lookup
> 1     F:/R/R-2.8.1/library/methods/libs/methods.dll          FALSE
> 2 F:/R/R-2.8.1/library/grDevices/libs/grDevices.dll          FALSE
> 3         F:/R/R-2.8.1/library/stats/libs/stats.dll          FALSE
> 4             F:/R/R-2.8.1/library/rgl/libs/rgl.dll           TRUE
>> library.dynam.unload("rgl", "F:/R/R-2.8.1/library/rgl")
> I say "sort of", in that I get no error messages and the dll is no longer
> locked in use as it normally would be in Windows, but reloading the package
> doesn't function properly. It's possible some combination of detach() and
> unloadNamespace() would get a clean unload, but really, I normally just quit
> R and restart.  It's pretty quick to start up, compared to the recompile
> time for the package.
> Duncan Murdoch
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Gabor Csardi <Gabor.Csardi at unil.ch>     UNIL DGM

More information about the R-help mailing list