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

John Chambers jmc at r-project.org
Wed Apr 3 23:58:13 CEST 2013


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



More information about the R-devel mailing list