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"
>>
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
Brian D. Ripley,                  [EMAIL PROTECTED]
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

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to