[Rd] Inspect a "delayed" assigned whose value throws an error?
Hadley Wickham
h.wickham at gmail.com
Tue Jan 27 16:03:09 CET 2015
On Tue, Jan 27, 2015 at 8:56 AM, Martin Maechler
<maechler at lynne.stat.math.ethz.ch> wrote:
>>>>>> Henrik Bengtsson <hb at biostat.ucsf.edu>
>>>>>> on Mon, 26 Jan 2015 12:41:48 -0800 writes:
>
> > On Mon, Jan 26, 2015 at 12:24 PM, Hadley Wickham <h.wickham at gmail.com> wrote:
> >> If it was any other environment than the global, you could use substitute:
> >>
> >> e <- new.env()
> >> delayedAssign("foo", stop("Hey!"), assign.env = e)
> >> substitute(foo, e)
> >>
> >> delayedAssign("foo", stop("Hey!"))
> >> substitute(foo)
>
> > Hmm... interesting and odd.
>
> > Unfortunately, this doesn't seem to help for reaching into the
> > namespace of hgu133a.db and inspecting 'hgu133aPFAM', e.g.
>
> >> library("hgu133a.db")
>
> >> substitute(hgu133aPFAM, env=ns)
> > Error: hgu133aPFAM is defunct. Please use select() if you need access to PFAM
> > or PROSITE accessions.
>
> >> evalq(substitute(hgu133aPFAM), envir=ns)
> > Error: hgu133aPFAM is defunct. Please use select() if you need access to PFAM
> > or PROSITE accessions.
>
> >> evalq(substitute(hgu133aPFAM, env=ns), envir=ns)
> > Error: hgu133aPFAM is defunct. Please use select() if you need access to PFAM
> > or PROSITE accessions.
>
> this *is* interesting..
>
> Note that shortly after delayedAssign() was introduced into R,
> we had
>
> R : Copyright 2005, The R Foundation for Statistical Computing
> Version 2.2.1 (2005-12-20 r36812)
> ISBN 3-900051-07-0
>
> ............
>
> > delayedAssign("x", pi^2) ; substitute(x)
> pi^2
> >
>
> so it also worked with the globalenv; but that feature already
> disappeared with
>
> R : Copyright 2006, The R Foundation for Statistical Computing
> Version 2.3.0 (2006-04-24)
>
> Almost surely as an inadvertent side effect of something else.
The substitute docs have: "If it is an ordinary variable, its value is
substituted, unless env is .GlobalEnv in which case the symbol is left
unchanged."
So it's definitely a deliberate change. This commit looks related:
https://github.com/wch/r-source/commit/182d197094f8fcecf6ec8f14bfc7c69a02ac251d.
There Duncan commented "For historical reasons, don't substitute in
R_GlobalEnv", which suggests that the behaviour you see in 2.2.1 might
have been a bug.
Hadley
--
http://had.co.nz/
More information about the R-devel
mailing list