Re: [Rd] Reference classes: accessor functions via 'getRefClass(...)$accessors(...)'

From: Vitalie S. <>
Date: Wed, 17 Nov 2010 13:50:52 +0100

"Janko Thyson" <> writes:

> Hi there,
> I'd like to choose between an "static" and "dynamic" access of a reference
> class field, say 'a'.
> myObj <- getRefClass("Blabla")$new()
> Static: myObj$a
> Dynamic: myObj$a.get() where the function retrieves the data
> from a database (or some other location), stores it to a buffer and
> optionally updates the static field value 'a'.
> I've set up such a method 'a.get()' where I can actually decide between
> static and dynamic runmode (so the method also wraps the call 'myObj$a' for
> the static runmode).
> Now I saw that setting up such accessor methods (get/set) is already done
> for me if I use 'getRefClass("Blabla")$accessors(.)'. I just don't
> understand what exactly I have to do there, because this results in an
> error: 'getRefClass("Blabla")$accessors("a")'
> Can anyone point me to the correct use of 'getRefClass(.)$accessors(.)'?

It works for me:

X <- setRefClass("XXX", fields = list(a = "character")) X$accessors("a")

# ...
# Class Methods:  
#    "callSuper", "export", "getA", "import", "initFields", "setA"
# ...

accessors() convenience method creates setA and getA functions:

x <- X$new()

#Class method definition for method getA()
#function () 
#<environment: 02a198c0>


> Thanks a lot,
> Janko
> [[alternative HTML version deleted]] mailing list Received on Wed 17 Nov 2010 - 12:55:00 GMT

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 Wed 17 Nov 2010 - 16:00:21 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive