Dear list,

I wonder how to write methods for the function 'as' in the sense that I 
can call 'as(object, Class, strict=TRUE, ext)' and let method dispatch 
figure out the correct method.

AFAIU, there is a difference between, e.g. 'as.data.frame' and the 
methods of 'as()' as stated above since the former depends on arg 'x' 
instead of 'object', 'Class' etc.?

 > methods("as")
 > as.data.frame

I have to admit that I'm not really familiar with the S3 style of 
defining methods as I have been coding in S4 a lot, but my first attempt 
was to write something like this:

as.myClass <- function(x, ...){
     if(is(x, "data.frame"){
         x <- as.list(x)
     }
     if(is(x, "character"){
         x <- as.list(x)
     }
     ...
     out <- getRefClass("myClass")$new(X=x)
     return(out)
}

But that way I'd have to explicitly call 'as.myClass(x)' whereas I'd 
simply like to type 'as(x, "myClass")'.
Also, how is it possible to have method dispatch recognize two  
signature arguments in S3? I.e., how can I define something like 
'as.data.frame.character' in order to have explicit "sub" methods for 
all the data types of 'x' so I wouldn't have to process them all in the 
definition of 'as.myClass' as I did above?

Thanks for your help,
Janko


-- 
------------------------------------------------------------------------

*Janko Thyson*
janko.thy...@googlemail.com <mailto:janko.thy...@googlemail.com>

Jesuitenstraße 3
D-85049 Ingolstadt

Mobile: +49 (0)176 83294257

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to