[Rd] Using missing() in a S4 method with extra arguments

From: Andreas Borg <andreas.borg_at_unimedizin-mainz.de>
Date: Fri, 11 Mar 2011 11:07:00 +0100


Hi all,

I have a function which makes use of missing() to determine which arguments are provided in the call - basically, there are two sets of arguments that map to different strategies the function uses to fulfill its task. After conversion to an S4 generic I've run into the problem that if a method uses extra arguments that are not in the signature of the generic, usage of missing() fails. The following example exemplifies this:

    setGeneric("fun", function(x=0, y=0, ...) standardGeneric("fun"))     # both methods should output if the second argument is missing     setMethod("fun", "character", function(x=0, y=0, ...) missing(y))     setMethod("fun", "numeric", function(x=0, y=0, z=0, ...) missing(y))

    fun("a") # this works fine
    fun(1) # this gives "FALSE

I've understood so far that this is due to the fact that the "numeric" method in this example is rewritten to:

    function (x = 0, y = 0, ...)
    {

.local <- function (x = 0, y = 0, z = 0, ...)

        missing(y)

.local(x, y, ...)

    }

The call to .local evaluates y and it is no more missing.

Is there any alternative that works in this case? Or is there a chance that missing() might be changed to work in this case in the near future?

Of course I know I could set NA or NULL as default values and check for these, but there are reasons I want to have legal default values for all arguments.

Best regards,

Andreas

Andreas Borg
Medizinische Informatik

UNIVERSITÄTSMEDIZIN
der Johannes Gutenberg-Universität
Institut für Medizinische Biometrie, Epidemiologie und Informatik Obere Zahlbacher Straße 69, 55131 Mainz
www.imbei.uni-mainz.de

Telefon +49 (0) 6131 175062
E-Mail: borg_at_imbei.uni-mainz.de

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und löschen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail und der darin enthaltenen Informationen ist nicht gestattet.



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 11 Mar 2011 - 10:11:15 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 Fri 11 Mar 2011 - 18:20:30 GMT.

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

list of date sections of archive