From hadley at rice.edu  Sun May  1 04:54:39 2011
From: hadley at rice.edu (Hadley Wickham)
Date: Sat, 30 Apr 2011 21:54:39 -0500
Subject: [Rd] Reference Classes: Accessing methods via [[...]], bug?
In-Reply-To: <SNT131-w42BCCDD218A68509A634CFB99D0@phx.gbl>
References: <SNT131-w42BCCDD218A68509A634CFB99D0@phx.gbl>
Message-ID: <BANLkTi=GvhhFmDT1=8sf0j6cM8Tsx3QJ9Q@mail.gmail.com>

If this message is garbled for anyone else, the original question on
stackoverflow is here:
http://stackoverflow.com/questions/5841339/using-notation-for-reference-class-methods

Hadley

On Sat, Apr 30, 2011 at 11:35 AM, Chad Goymer <chad.goymer at hotmail.co.uk> wrote:
>
> I've been trying to use methods for reference classes via the notation "[[...]]" (X[["doSomething"]] rather than X$doSomething), but it failed to work. However, I did find that if you use the usual "$" notation first, "[[...]]" can be used afterwards. The following simple example illustrates the point:
>> setRefClass("Number", + ? fields = list(+ ? ? value = "numeric"+ ? ),+ ? methods = list(+ ? ? addOne = function() {+ ? ? ? value <<- value + 1+ ? ? }+ ? )+ )> X <- new("Number", value = 1)> X[["value"]][1] 1
>> X[["addOne"]]()Error: attempt to apply non-function> class(X[["addOne"]]) # NULL[1] "NULL"
>> class(X$addOne)[1] "refMethodDef"attr(,"package")[1] "methods"
>> X[["addOne"]]()> X[["value"]][1] 2> class(X[["addOne"]])[1] "refMethodDef"attr(,"package")[1] "methods"
> Is this a bug?
> Chad Goymer
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



[Rd] Reference Classes: Accessing methods via [[...]], bug?
Hadley Wickham