Skip to content
Back to formatted view

Raw Message

Message-ID: <FA387FE8-4AF7-4A6C-A4D2-F3F51DE43D6D@r-project.org>
Date: 2013-04-03T21:58:13Z
From: John Chambers
Subject: Redefining quote() with reference classes (was: Ref classes initFields has incorrect environment?)
In-Reply-To: <3FB0FB82-F3E3-4911-93B9-D2729246AC94@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