Herve Pages
2008-Sep-09 17:57 UTC
[Rd] Defining an alias for a generic function and callNextMethod() strange behaviour
Hi,
My package contains the following foo() generic and methods (simplified
version):
setGeneric("foo", signature="x", function(x, y=NA)
standardGeneric("foo"))
setMethod("foo", "ANY", function(x, y=NA) list(x, y))
setMethod("foo", "character", function(x, y=NA)
unlist(callNextMethod()))
> foo(5)
[[1]]
[1] 5
[[2]]
[1] NA
> foo("a")
[1] "a" NA
And I want to define a temporary alias for foo() for backward
compatibility with some existing code:
oldfoo <- function(...) { .Deprecated("foo"); foo(...) }
> oldfoo(5)
[[1]]
[1] 5
[[2]]
[1] NA
Warning message:
'oldfoo' is deprecated.
Use 'foo' instead.
See help("Deprecated")
> oldfoo("a")
Error in .nextMethod() : argument "x" is missing, with no default
In addition: Warning message:
'oldfoo' is deprecated.
Use 'foo' instead.
See help("Deprecated")
Why isn't this working?
One way to make this work is to specify the arguments in the call
to callNextMethod(), or in the definition of the oldfoo alias.
But wouldn't that be nice to be able to just use
fooalias <- function(...) foo(...) for aliasing?
Thanks!
H.
R version 2.7.0 (2008-04-22)
i686-pc-linux-gnu
locale:
LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
