From jmc at r-project.org  Wed Oct  4 15:52:21 2006
From: jmc at r-project.org (John Chambers)
Date: Wed, 04 Oct 2006 09:52:21 -0400
Subject: [Rd] Default argument value for "["
In-Reply-To: <1159957901.14595.24.camel@localhost.localdomain>
References: <mailman.9.1159956004.28879.r-devel@r-project.org>
	<1159957901.14595.24.camel@localhost.localdomain>
Message-ID: <4523BC95.6010505@r-project.org>

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




[Rd] Default argument value for "["
John Chambers