[Rd] Default argument value for "["
John Chambers
jmc at r-project.org
Wed Oct 4 15:52:21 CEST 2006
I think the problem in your case comes from the mechanism used to handle
non-standard argument lists; notice that you have added 3 new
arguments. If you look at the body of the resulting method you will see
that the mechanism used to handle this (defining a function .local)
fails to copy the default value from the method, as in the simpler
example below:
> setMethod("[", c("mm"), function(x, i, j, k..., drop=FALSE)browser())
[1] "["
> selectMethod("[", "mm")
Method Definition:
function (x, i, j, ..., drop = TRUE)
{
.local <- function (x, i, j, k..., drop = FALSE)
browser()
.local(x, i, j, ..., drop = drop)
}
We can probably fix this. Meanwhile, the workaround is to use the same
mechanism yourself, but get the default value right. Define your
method as a function (like the .local you see when printing the current
method) and then define a method with the formally correct arguments
(function(x, i, j, ..., drop=FALSE)) and call your function from that
method.
Beware there is _another_ related "bug": if you use callNextMethod(),
it does not seem to copy the default value of drop= either. (It's a bit
more debatable what callNextMethod() with no arguments should do in this
case, so the problem here may be an "undesired feature" rather than a
bug.) You didn't show your real method, so this may not apply in your
example.
By the way, I would be a little surprised if this had anything to do
with changes in 2.4.0, at least those I'm aware of.
Iago Mosqueira wrote:
> Dear all,
>
> After installing R 2.4.0, a definition of "[" for an S4 class has
> stopped working as the default for drop in the generic, TRUE, appears to
> override the default in the method
>
> The method is defined for demonstration purposes as
>
> setMethod("[", signature(x="FLQuant"),
> function(x, i="missing", j="missing", k="missing", l="missing",
> m="missing", ..., drop=FALSE) {
>
> print(drop)
> }
> )
>
> When called as
>
> new('FLQuant')[1,]
>
> drop is TRUE, instead of FALSE. Am I missing something? Has there been a
> change in R 2.4.0 of relevance here? I could not find it in the NEWS
> file.
>
> Many thanks,
>
>
> Iago Mosqueira
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
More information about the R-devel
mailing list