From ggrothendieck at gmail.com  Fri Sep  8 18:12:55 2006
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Fri, 8 Sep 2006 12:12:55 -0400
Subject: [Rd] Extending [ method to S4 class and drop argument (PR#9211)
In-Reply-To: <20060908160424.636BECCD9@slim.kubism.ku.dk>
References: <20060908160424.636BECCD9@slim.kubism.ku.dk>
Message-ID: <971536df0609080912w386d56d7vf9d064ccfa999dfe@mail.gmail.com>

Try this:

> setClass("test",representation(x="character"))
[1] "test"
> setMethod("[","test",function(x,i,j,...,drop) {
+    print(i)
+    if (missing(drop)) drop <- TRUE
+    print(drop)
+ })
[1] "["
> a = new("test",x="fred")
> a[1]
[1] 1
[1] TRUE


On 9/8/06, jverzani at gmail.com <jverzani at gmail.com> wrote:
> Full_Name: John Verzani
> Version: 2.4.0 alpha (2006-09-05 r39134)
> OS: linux, gentoo 2.6.17
> Submission from: (NULL) (163.238.43.26)
>
>
> When extending the "[" method to a new S4 class, the default value for the drop
> argument is not being found. Here is a small example:
>
> setClass("test",representation(x="character"))
> setMethod("[","test",function(x,i,j,...,drop=TRUE) {print(i);print(drop)})
> a = new("test",x="fred")
> a[1]
>
> resulting in:
>
> [1] 1
> Error in print(drop) : argument "drop" is missing, with no default
>
> I'm expecting TRUE for the value of drop. That's correct isn't?
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>




[Rd] Extending [ method to S4 class and drop argument (PR#9211)
Gabor Grothendieck