From btyner @end|ng |rom gm@||@com  Sat Nov  6 14:51:31 2021
From: btyner @end|ng |rom gm@||@com (Benjamin Tyner)
Date: Sat, 6 Nov 2021 09:51:31 -0400
Subject: [Rd] S4 methods with default argument of NULL
Message-ID: <a6157cb1-fd0b-63dd-55eb-496933e1a61e@gmail.com>

Greetings,

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, ...) {

     ????????????? force(y)
     ????????????? 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 
found")

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
    standards)

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

    https://github.com/DyfanJones/noctua/issues/170

Any comments to shed some light would be greatly appreciated.

Regards,

Ben



[Rd] S4 methods with default argument of NULL
Benjamin Tyner