[Rd] S4 packages and .Rdata file.

John Chambers jmc at R-project.org
Mon Jan 31 22:32:06 CET 2005

Witold Eryk Wolski wrote:

> Dear developers.
> Have spend just 1 h searching for a bug in a new version of a new 
> version of a package.
> I was getting a segfault all the time. "Funny" thing - there was no 
> error neither in the S nor in the C code.
> To solve the problem I had to delete the .Rdata file!
> What I observed. If the .Rdata file was generated while a previous 
> release of a package was installed  in the .Rdata file the S4 classes 
> and methods definition are stored  for some reasons. It may be of course 
> that I have sourced the method definition what would explain why they 
> are in .Rdata.  More interestingly is that even if loading a new version 
> of a package with library(msbase)
> the function definitions stored in .Rdata precede the methods of the 
> newly loaded package in the search path. They are called instead of the 
> new method definitions (?).

When you save a workspace image, that includes method definitions done 
in the global environment (as you would certainly want it to).  The 
objects have special names in order to follow the "metadata" semantics 
in "Programming with Data" and also not to conflict with ordinary objects.

If you _don't_ want to save methods for function "f", use 
removeMethods("f") before saving and quitting.

To find out what functions have methods defined in the global 
environment, use getGenerics(1).  Then you can use removeMethods() for 
those functions & resave the workspace image.

If the function "f" has methods in other packages as well, use
   removeMethods("f", all=FALSE)
to remove only the methods object in the global environment.

And if you like the grubby but direct approach, do
which will show methods lists as objects with names starting with 
".__M__".  You can remove those objects using the list= argument to rm().

> So If I wass calling what I thought is the new version of the method the 
> old method stored months ago in the .Rdata file was called again and again.
> Is not there a better way to avoid such problems than deleting the 
> .Rdata file?
> Eryk

More information about the R-devel mailing list