From soeren.vogel at uzh.ch  Fri Jun 10 11:10:48 2011
From: soeren.vogel at uzh.ch (soeren.vogel at uzh.ch)
Date: Fri, 10 Jun 2011 11:10:48 +0200
Subject: [Rd] Reference Classes, Generator Object
Message-ID: <DF31719B-E5DC-4BD2-AB55-FE3114D5F397@uzh.ch>

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



[Rd] Reference Classes, Generator Object
soeren.vogel at uzh.ch