[Rd] [R] type converters not being saved to workspace

John Chambers jmc at r-project.org
Tue Apr 11 22:22:50 CEST 2006


(diverted to r-devel)

The problem seems to be rather that loading of the saved image takes 
place _after_ the packages are attached.  So nothing that the methods 
package does in its initialization will see the relevant type converters 
or other methods objects.

More generally, loading into .GlobalEnv will never cause the equivalent 
of cacheMetaData(.GlobalEnv).

It would be possible to hack the C code in main/saveload.c to generate a 
call to cacheMetaData under the right circumstances, but is that the 
best solution? 

Intuitively, it's the objects containing the method/class definitions 
that should trigger actions when they are loaded (emulating what happens 
when the corresponding setMethod or setClass function call takes 
place).  I.e., a load method for these classes of objects.  Possible?

It might be better, now that we're past feature freeze, to leave this as 
a "design infelicity" for the upcoming release.


Prof Brian Ripley wrote:

> It is recommended that you use a package for this sort of thing.
>
> When a package is loaded, the S4 methods it contains are merged into 
> the metadata.  When the global environment is loaded, they are not.  
> Call 'cacheMetaData(1)' to do so.
>
> [This looks like a bug: cacheMetaData is called on .GlobalEnv in the 
> startup code for package methods, but seems not to work when called 
> from there.  I think this is because package methods is not at that 
> point on the search path (the call is from .onLoad) and hence the 
> coerce() generic is not visible to cacheMetaData.  If you have S4 code 
> in a package, it will ensure that package methods is attached before 
> your package is loaded.]
>
> On Sun, 9 Apr 2006, Joseph Wang wrote:
>
>> Any one can explain why this happens or any work arounds?
>>
>>> setClass('foo')
>>
>> [1] "foo"
>>
>>> setAs('foo', 'character', function(from) from)
>>> showMethods('coerce')
>>
>>
>> Function "coerce":
>> from = "ANY", to = "array"
>> from = "ANY", to = "call"
>> from = "ANY", to = "character"
>> from = "ANY", to = "complex"
>> from = "ANY", to = "environment"
>> from = "ANY", to = "expression"
>> from = "ANY", to = "function"
>> from = "ANY", to = "integer"
>> from = "ANY", to = "list"
>> from = "ANY", to = "logical"
>> from = "ANY", to = "matrix"
>> from = "ANY", to = "name"
>> from = "ANY", to = "numeric"
>> from = "ANY", to = "single"
>> from = "ANY", to = "ts"
>> from = "ANY", to = "vector"
>> from = "ANY", to = "NULL"
>> from = "foo", to = "character"
>>
>>> q()
>>
>> Save workspace image? [y/n/c]: y
>>
>>
>> (restart)
>>
>>> showMethods('coerce')
>>
>>
>> Function "coerce":
>> from = "ANY", to = "array"
>> from = "ANY", to = "call"
>> from = "ANY", to = "character"
>> from = "ANY", to = "complex"
>> from = "ANY", to = "environment"
>> from = "ANY", to = "expression"
>> from = "ANY", to = "function"
>> from = "ANY", to = "integer"
>> from = "ANY", to = "list"
>> from = "ANY", to = "logical"
>> from = "ANY", to = "matrix"
>> from = "ANY", to = "name"
>> from = "ANY", to = "numeric"
>> from = "ANY", to = "single"
>> from = "ANY", to = "ts"
>> from = "ANY", to = "vector"
>> from = "ANY", to = "NULL"
>> from = "NULL", to = "OptionalFunction"
>>
>>>
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! 
>> http://www.R-project.org/posting-guide.html
>>
>



More information about the R-devel mailing list