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.goy...@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@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/ ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel