[Rd] How to do package cleanup: hooks .onUnload, R_unload_mylib, .onDetach are not called on quit

Renaud Gaujoux renaud at mancala.cbio.uct.ac.za
Wed Nov 6 11:26:37 CET 2013


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).

  * 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.
  * 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?

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
>



More information about the R-devel mailing list