[Rd] Reference Classes, Generator Object
soeren.vogel at uzh.ch
soeren.vogel at uzh.ch
Fri Jun 10 11:10:48 CEST 2011
Hello, I am working with a reference class:
Foo <- setRefClass("Bar",
fields = list( a = "numeric"),
methods = list( baz = function( xa ) a <<- xa )
)
x <- Foo$new()
x$baz(2)
x$a
y <- new("Bar")
y$baz(4)
y$a
But that might be confusing, since new(Foo) does not work and neither does Bar$new() (which is both clear to me but -- maybe -- not to the user). So my idea was to:
Bar <- setRefClass("Bar",
fields = list( a = "numeric"),
methods = list( baz = function( xa ) a <<- xa )
)
x <- Bar$new()
x$baz(2)
x$a
y <- new("Bar")
y$baz(4)
y$a
However, this is not the way it is usually done (e.g., with Rcpp modules), why not? Thanks, Sören
More information about the R-devel
mailing list