From pdalgd at gmail.com  Wed Mar 21 00:58:20 2012
From: pdalgd at gmail.com (peter dalgaard)
Date: Wed, 21 Mar 2012 00:58:20 +0100
Subject: [Rd] Substitute adds id attribute?
In-Reply-To: <CABdHhvEKaDNRDjf-3Rp=b=wvnMO-ZNvk8aLge9-U6K8BkJz4Sg@mail.gmail.com>
References: <CABdHhvEKaDNRDjf-3Rp=b=wvnMO-ZNvk8aLge9-U6K8BkJz4Sg@mail.gmail.com>
Message-ID: <4D12E7A7-015E-44BC-8C93-C3199078B144@gmail.com>


On Mar 20, 2012, at 22:31 , Hadley Wickham wrote:

> Hi all,
> 
> I can't figure out how to make this problem easily reproducible, but I
> can demonstrate it very simply, so I hoped someone might be able to
> suggest a place to start:
> 
>> f <- function(x) substitute(x)
>> f(x)
> x
>> f(mpg)
> mpg
> attr(,"id")
> [1] 11
> 
> It works as expected in a clean R session:
> 
>> f <- function(x) substitute(x)
>> f(x)
> x
>> f(mpg)
> mpg
> 
> but not after the following code
> 
> library(devtools)
> install_github("staticdocs")
> library(staticdocs)
> build_package("ggplot2", tempdir())
> 
> Any ideas?
> 

Well, yes; you can get there more quickly as follows:

> x <- as.name("foo")
> attr(x,"id") <- 7913
> x
foo
attr(,"id")
[1] 7913
> substitute(foo)
foo
attr(,"id")
[1] 7913

I.e. if you ever put an attribute on a symbol, it stays there "forever". The fix is probably to forbid setting attributes on symbols (as we already do for environments and NULL) but I bet that breaks something...
 




> Thanks,
> 
> Hadley
> 
> -- 
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice University
> http://had.co.nz/
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] Substitute adds id attribute?
peter dalgaard