Re: [R] deparse, substitute and S4 generics

From: <Bill.Venables_at_csiro.au>
Date: Wed, 23 Jan 2008 09:56:31 +1000

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. Received on Tue 22 Jan 2008 - 23:58:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 Jan 2008 - 00:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive