Using .onUnload() to unload compiled code

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using .onUnload() to unload compiled code

James W. MacDonald
If one wants to unload compiled code for a package containing a namespace, my understanding is that .onUnload() should be used, with a call to library.dynam.unload(). This is used in e.g., the stats and methods packages, but it appears to me that the compiled code is not being unloaded when the package is detached(). Am I misunderstanding something?

Best,

Jim

> search()
[1] ".GlobalEnv"        "package:methods"   "package:stats"     "package:graphics"
[5] "package:grDevices" "package:utils"     "package:datasets"  "Autoloads"        
[9] "package:base"    

> stats:::.onUnload
function (libpath)
library.dynam.unload("stats", libpath)
<environment: namespace:stats>

> getLoadedDLLs()
                                                   Filename Dynamic.Lookup
base                                                   base          FALSE
iconv                        C:/rw2030dev/modules/iconv.dll           TRUE
grDevices C:/rw2030dev/library/grDevices/libs/grDevices.dll          FALSE
stats             C:/rw2030dev/library/stats/libs/stats.dll          FALSE
methods       C:/rw2030dev/library/methods/libs/methods.dll          FALSE

> detach(3)

> search()
[1] ".GlobalEnv"        "package:methods"   "package:graphics"  "package:grDevices"
[5] "package:utils"     "package:datasets"  "Autoloads"         "package:base"  
   
> getLoadedDLLs()
                                                   Filename Dynamic.Lookup
base                                                   base          FALSE
iconv                        C:/rw2030dev/modules/iconv.dll           TRUE
grDevices C:/rw2030dev/library/grDevices/libs/grDevices.dll          FALSE
stats             C:/rw2030dev/library/stats/libs/stats.dll          FALSE
methods       C:/rw2030dev/library/methods/libs/methods.dll          FALSE

> R.version
               _                                                            
platform       i386-pc-mingw32                                              
arch           i386                                                          
os             mingw32                                                      
system         i386, mingw32                                                
status         Under development (unstable)                                  
major          2                                                            
minor          3.0                                                          
year           2006                                                          
month          01                                                            
day            01                                                            
svn rev        36947                                                        
language       R                                                            
version.string Version 2.3.0 Under development (unstable) (2006-01-01 r36947)


James W. MacDonald
Affymetrix and cDNA Microarray Core
University of Michigan Cancer Center
1500 E. Medical Center Drive
7410 CCGC
Ann Arbor MI 48109
734-647-5623



**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Using .onUnload() to unload compiled code

Seth Falcon-2
Hi Jim,

On  8 Feb 2006, [hidden email] wrote:
> If one wants to unload compiled code for a package containing a
> namespace, my understanding is that .onUnload() should be used, with
> a call to library.dynam.unload(). This is used in e.g., the stats
> and methods packages, but it appears to me that the compiled code is
> not being unloaded when the package is detached(). Am I
> misunderstanding something?

A package with a namespace can be loaded and not attached or loaded
and attached.

Use loadedNamespaces() to see what is loaded, and search() to see
what is attached.

.Last.lib() gets called by detach() is called.  .onUnload() is called
by unloadNamespace().  I'm pretty sure you can have both .Last.lib and
.onUnload in a package with a namespace.

hth,

+ seth

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Using .onUnload() to unload compiled code

Brian Ripley
In reply to this post by James W. MacDonald
On Wed, 8 Feb 2006, James MacDonald wrote:

> If one wants to unload compiled code for a package containing a
> namespace, my understanding is that .onUnload() should be used, with a
> call to library.dynam.unload(). This is used in e.g., the stats and
> methods packages, but it appears to me that the compiled code is not
> being unloaded when the package is detached(). Am I misunderstanding
> something?

No. It is still needed whilst the namespace is loaded.  .onUnload is not
run by detach(), but by unloadNamespace


>
> Best,
>
> Jim
>
>> search()
> [1] ".GlobalEnv"        "package:methods"   "package:stats"     "package:graphics"
> [5] "package:grDevices" "package:utils"     "package:datasets"  "Autoloads"
> [9] "package:base"
>
>> stats:::.onUnload
> function (libpath)
> library.dynam.unload("stats", libpath)
> <environment: namespace:stats>
>
>> getLoadedDLLs()
>                                                   Filename Dynamic.Lookup
> base                                                   base          FALSE
> iconv                        C:/rw2030dev/modules/iconv.dll           TRUE
> grDevices C:/rw2030dev/library/grDevices/libs/grDevices.dll          FALSE
> stats             C:/rw2030dev/library/stats/libs/stats.dll          FALSE
> methods       C:/rw2030dev/library/methods/libs/methods.dll          FALSE
>
>> detach(3)
>
>> search()
> [1] ".GlobalEnv"        "package:methods"   "package:graphics"  "package:grDevices"
> [5] "package:utils"     "package:datasets"  "Autoloads"         "package:base"
>
>> getLoadedDLLs()
>                                                   Filename Dynamic.Lookup
> base                                                   base          FALSE
> iconv                        C:/rw2030dev/modules/iconv.dll           TRUE
> grDevices C:/rw2030dev/library/grDevices/libs/grDevices.dll          FALSE
> stats             C:/rw2030dev/library/stats/libs/stats.dll          FALSE
> methods       C:/rw2030dev/library/methods/libs/methods.dll          FALSE
>
>> R.version
>               _
> platform       i386-pc-mingw32
> arch           i386
> os             mingw32
> system         i386, mingw32
> status         Under development (unstable)
> major          2
> minor          3.0
> year           2006
> month          01
> day            01
> svn rev        36947
> language       R
> version.string Version 2.3.0 Under development (unstable) (2006-01-01 r36947)
>
>
> James W. MacDonald
> Affymetrix and cDNA Microarray Core
> University of Michigan Cancer Center
> 1500 E. Medical Center Drive
> 7410 CCGC
> Ann Arbor MI 48109
> 734-647-5623
>
>
>
> **********************************************************
> Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel