[Rd] How to do package cleanup: hooks .onUnload, R_unload_mylib, .onDetach are not called on quit
Duncan Murdoch
murdoch.duncan at gmail.com
Wed Nov 6 12:36:59 CET 2013
On 13-11-06 5:26 AM, Renaud Gaujoux wrote:
> Hi,
>
> it seems that the package hooks .onLoad and its C++ pendant
> R_unload_mylib are actually not called when R quits, but only when
> explicitly calling detach('package:mylib', unload = TRUE).
> Maybe this is platform specific, I'm on Ubuntu 13.10 - R 3.0.2 (see below).
No, this is by design. See ?setHook.
>
> * is there a mechanism that a package can use to effectively do some
> cleanup on standard exit, such as calling cleaning up routines of a
> loaded third-party library? I tried .onDetach but it did not work
> either.
Yes, you can set a finalizer. See ?reg.finalizer.
> * by curiosity, in what kind of practical situation would a user
> want to call detach(..., unload = TRUE)?
> * is there a reason why the hooks are not called on quit?
They are slow to run, and are usually not needed. Finalizers handle the
rare cases where you really do need something to happen.
Duncan Murdoch
>
> Thank you.
>
> Bests,
> Renaud
>
> ###
>> Sys.info()
>
> sysname release
> version
> "Linux"
> "3.11.0-12-generic" "#19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013"
> nodename
> machine login
> "XXXXX"
> "x86_64" "renaud"
> user
> effective_user
> "renaud"
> "renaud"
>> sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
> LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
> LC_MONETARY=en_US.UTF-8
> [6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
> LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
More information about the R-devel
mailing list