[R] deparse, substitute and S4 generics

Michał Bojanowski M.J.Bojanowski at uu.nl
Wed Jan 23 01:09:13 CET 2008


Hello Bill,

Thanks! Indeed that works. Can you give me a hunch why?
Does it have anything to do with environments and scope?

~michal



Bill.Venables wrote:
> 
> Try putting a ... argument in the method for g as well
> 
> setGeneric("g", function(object, ...) standardGeneric("g"))
> 
> setMethod("g", "ANY",
> function(object, ...)  ### change
> {
>     nam <- deparse(substitute(object))
>     cat("name:", nam, "\n")
>     object
> } ) 
> 
> 
> Now it works.
> 
> Bill Venables
> CSIRO Laboratories
> PO Box 120, Cleveland, 4163
> AUSTRALIA
> Office Phone (email preferred): +61 7 3826 7251
> Fax (if absolutely necessary):  +61 7 3826 7304
> Mobile:                         +61 4 8819 4402
> Home Phone:                     +61 7 3286 7700
> mailto:Bill.Venables at csiro.au
> http://www.cmis.csiro.au/bill.venables/ 
> 
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Bojanowski, M.J. (Michal)
> Sent: Wednesday, 23 January 2008 9:48 AM
> To: r-help at r-project.org
> Subject: [R] deparse, substitute and S4 generics
> 
> Hello everyone,
> 
> I encountered the following confusing behavior of 'deparse' and
> 'substitute' while programming with S4 classes (see example below). It
> seems like the presence of '...' argument in the definition of the
> generic generates the problem. I have no clue why, can anyone explain
> that to me? Are there any "workarounds"?
> 
> Thanks a lot for your time!
> 
> ~Michal
> 
> 
> 
> # Let's define two seemingly identical generics
> 
> setGeneric("f", function(object) standardGeneric("f"))
> 
> setMethod("f", "ANY",
> function(object)
> {
>     nam <- deparse(substitute(object))
>     cat("name:", nam, "\n")
>     object
> } )
> 
> # and
> 
> setGeneric("g", function(object, ...) standardGeneric("g"))
> 
> setMethod("g", "ANY",
> function(object)
> {
>     nam <- deparse(substitute(object))
>     cat("name:", nam, "\n")
>     object
> } )
> 
> 
> 
> # now let's test:
> 
> x <- 1
> 
> # this works
> f(x)
> 
> # but this does not,  why? what '...' has to do with it?
> g(x)
> 
> 
> 
> ____________________________________
> Michal Bojanowski
> ICS / Department of Sociology
> Utrecht University
> Heidelberglaan 2; 3584 CS Utrecht
> The Netherlands
> m.j.bojanowski at uu dot nl
> http://www.fss.uu.nl/soc/bojanowski/
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.
> 
> ______________________________________________
> R-help at 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.
> 
> 


-----
____________________________________
Michal Bojanowski
ICS / Department of Sociology
Utrecht University
Heidelberglaan 2; 3584 CS Utrecht
The Netherlands
m.j.bojanowski at uu dot nl
http://www.fss.uu.nl/soc/bojanowski/
http://bojan.3e.pl
-- 
View this message in context: http://www.nabble.com/deparse%2C-substitute-and-S4-generics-tp15031691p15031992.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list