From jmc at r-project.org  Fri Oct 22 20:30:54 2010
From: jmc at r-project.org (John Chambers)
Date: Fri, 22 Oct 2010 11:30:54 -0700
Subject: [Rd] Reference classes
In-Reply-To: <4CC1CFFE.5080402@r-project.org>
References: <AANLkTik+o=SgwXO5augahHC18Hv9hBL87VOyGVG8LqN_@mail.gmail.com>
	<4CC1CFFE.5080402@r-project.org>
Message-ID: <4CC1D85E.8080700@r-project.org>

One correction:

On 10/22/10 10:55 AM, John Chambers wrote:
.....

>> As a suggestion, it would be nice if the accessors() method could be
>> used to create just "getters" or just "setters" for particular fields,
>> although I realise this can be worked around by removing the unwanted
>> methods afterwards.
>
> In other words, read-only fields. There is a facility for that
> implemented already, but it didn't yet make it into the documentation,
> and it could use some more testing. The generator object has a $lock()
> method that inserts a write-once type of method for one or more fields.
> Example:
>
>  > fg <- setRefClass("foo", list(bar = "numeric", flag = "character"),
> + methods = list(
> + addToBar = function(incr) {
> + b = bar + incr
> + bar <<- b
> + b
> + }
> + ))
>  > fg$lock("bar")
>  > ff = new("foo", bar = 1.5)
>  > ff$bar <- 2
> Error in function (value) : Field "bar" is read-only
>
>

Actually it is documented in the section on generator objects.  But 
since I also didn't see it, maybe it needs an example.  ;-)

John



[Rd] Reference classes
John Chambers