An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20110430/9dd50b16/attachment.pl>
Reference Classes: Accessing methods via [[...]], bug?
2 messages · Chad Goymer, Hadley Wickham
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/