From jmc at r-project.org  Wed Apr  3 23:58:13 2013
From: jmc at r-project.org (John Chambers)
Date: Wed, 3 Apr 2013 14:58:13 -0700
Subject: [Rd] Redefining quote() with reference classes (was: Ref
	classes initFields has incorrect environment?)
In-Reply-To: <3FB0FB82-F3E3-4911-93B9-D2729246AC94@r-project.org>
References: <CABdHhvFOcTbX0YnQ8Uiz6C_QdWX_hu9kuA7gD8XgDLg+voEzrQ@mail.gmail.com>
	<3FB0FB82-F3E3-4911-93B9-D2729246AC94@r-project.org>
Message-ID: <FA387FE8-4AF7-4A6C-A4D2-F3F51DE43D6D@r-project.org>

This should now be fixed in r-devel and 3.0.0 Patched as of revision 62487.

On Mar 29, 2013, at 11:30 AM, John Chambers <jmc at r-project.org> wrote:

> Nothing to do with initFields.  If you trace your redefined quote(), it's called from the <<- assignment of x.
> 
> The "x" element in the environment for the reference class object is implemented as an active binding in order to enforce the class when assigning the field.
> 
> Effectively that makes the assignment behave like a reference class method, and so ends up doing as() and getting back to the malware version of quote().
> 
> The fix will be to  have a more bullet proof (and perhaps more efficient) version of the active binding generated for fields.  A better design anyway, but this will take a little re-organization because the current default binding function is generated by some code manipulation.
> 
> Meanwhile the workaround is: Don't do what the revised subject heading says.
> 
> John
> 
> 
> On Mar 28, 2013, at 11:40 AM, Hadley Wickham <h.wickham at gmail.com> wrote:
> 
>> As suggested by the following code:
>> 
>> A <- setRefClass("A", fields = list(x = "logical"),
>> methods = list(initialize = function(...) {
>>   x <<- FALSE
>>   initFields(...)
>> }))
>> A$new()
>> # Works as expected
>> 
>> quote <- as.character
>> A$new()
>> # Error in function (value)  :
>> #  invalid replacement for field ?x?, should be from class ?logical?
>> or a subclass (was class ?character?)
>> 
>> I get the same error in:
>> * R version 2.15.2 (2012-10-26)
>> * R version 2.15.3 (2013-03-01)
>> * R Under development (unstable) (2013-03-28 r62432)
>> 
>> Hadley
>> 
>> -- 
>> Chief Scientist, RStudio
>> http://had.co.nz/
>> 
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Redefining quote() with reference classes (was: Ref classes initFields has incorrect environment?)
John Chambers