Re: [Rd] symbol name caching bug: attributes get tied to symbol names

From: John Chambers <jmc_at_r-project.org>
Date: Sun, 14 Mar 2010 16:21:13 -0700

Just to note, S4 classes can be defined to extend symbols (class "name") and other reference types. These work by using a hidden slot for the reference object, just to avoid attaching attributes to the reference. (Discussed briefly in the section on Basic Classes in ?Classes.)

John

William Dunlap wrote:
>> -----Original Message-----
>> From: luke@stat.uiowa.edu [mailto:luke@stat.uiowa.edu]
>> Sent: Friday, March 12, 2010 4:24 PM
>> To: William Dunlap
>> Cc: r-devel_at_r-project.org
>> Subject: Re: [Rd] symbol name caching bug: attributes get
>> tied to symbol names
>>
>> Since symbols/names are reference objects this behavior in unavoidable
>> if we allow attributes to be added to them. On the other hand, I'm
>> not sure it makes sense to allow that. Attempting to set an attribute
>> on NULL signals an error; it would probably make sense to do the same
>> for any name object.
>>
>>
>
> Thanks Luke, for the explanation.
>
> I'm comfortable disallowing attributes on names.
>
> The problem arose for me when analyzing a parse
> tree and I was using attributes to label parts of it.
> I can stick in a list() layer above the calls, names,
> etc., to attach the attributes to. That can simplify
> the syntax also, since things like as.vector() applied
> to a call object with attributes won't strip the attributes.
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
>> luke
>>
>> On Fri, 12 Mar 2010, William Dunlap wrote:
>>
>>
>>> In R versions 2.10.1 and "2.11.0 Under development
>>> (unstable) (2010-03-07 r51225)" on Windows I get the
>>> following if I type the commands at the start of
>>> the session. Note how the attribute attached to
>>> the name "Response" by the initial call to structure()
>>> seems to get tied to that name for the remainder of
>>> the session:
>>>
>>> > z <- structure(quote(Response), isResponse=TRUE)
>>> > parse(text="Response~Predictor")[[1]][[2]]
>>> Response
>>> attr(,"isResponse")
>>> [1] TRUE
>>> > quote(Response~Predictor)[[2]]
>>> Response
>>> attr(,"isResponse")
>>> [1] TRUE
>>> > quote(Response)
>>> Response
>>> attr(,"isResponse")
>>> [1] TRUE
>>>
>>> The attribute actually does go away after quite a
>>> while, but I haven't figured out the trigger.
>>> rm(z) followed by gc() does not affect it.
>>>
>>> If I use an unadorned variable called Response before
>>> making the structure z, then the isResponse attribute
>>> doesn't seem to stick to the name Response.
>>>
>>>
>>> Bill Dunlap
>>> Spotfire, TIBCO Software
>>> wdunlap tibco.com
>>>
>>> ______________________________________________
>>> R-devel_at_r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>>
>> --
>> Luke Tierney
>> Chair, Statistics and Actuarial Science
>> Ralph E. Wareham Professor of Mathematical Sciences
>> University of Iowa Phone: 319-335-3386
>> Department of Statistics and Fax: 319-335-3017
>> Actuarial Science
>> 241 Schaeffer Hall email: luke_at_stat.uiowa.edu
>> Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
>>
>>
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun 14 Mar 2010 - 23:23:44 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 Mon 15 Mar 2010 - 10:41:02 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive