[Rd] Reference Classes, Generator Object

From: <soeren.vogel_at_uzh.ch>
Date: Fri, 10 Jun 2011 11:10:48 +0200


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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 10 Jun 2011 - 09:14:27 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 10 Jun 2011 - 11:10:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive