[Rd] S4 methods with default argument of NULL

Benjamin Tyner btyner @end|ng |rom gm@||@com
Sat Nov 6 14:51:31 CET 2021


I noticed that starting with R version 3.5.0, it is now possible to do, 
for example:

    setGeneric(name = "foo",
                def = function(x, y, ...) standardGeneric("foo"),
                valueClass = "fooResult"

    setMethod(f = "foo",
               signature = c("character", "character"),
               definition = function(x, y = NULL, z = NULL, ...) {

                   message(sprintf("x is %s", x))

                   structure(list(), class = "fooResult")

    foo("a", "b") # this works in R >= 3.5.0, but fails in R < 3.5.0

(Prior to R version 3.5.0, it gives "Error in force(y) : object 'y' not 

I am curious to learn whether the change permitting this was:

    1. an intentional enhancement
    2. unintentional, but a "happy accident" (i.e., a desirable side
    effect of some other enhancement)
    3. unintentional, and perhaps undesirable (i.e., a loosening of

For reference, this came up in the debugging of the following issue:


Any comments to shed some light would be greatly appreciated.



More information about the R-devel mailing list