From h.wickham at gmail.com  Tue Jan 27 16:03:09 2015
From: h.wickham at gmail.com (Hadley Wickham)
Date: Tue, 27 Jan 2015 09:03:09 -0600
Subject: [Rd] Inspect a "delayed" assigned whose value throws an error?
In-Reply-To: <21703.42771.678057.885871@stat.math.ethz.ch>
References: <CAFDcVCQiE=DEJuNMAd2xZfQF-Cz3fyx4ajTwmeBvncwmcsS8oA@mail.gmail.com>
	<CABdHhvFHgnb9mHKQO7L_DQybVHcA7vQqwCuuj7=3cra3_ZXfzg@mail.gmail.com>
	<CAFDcVCSNWk9Yh_DMe=nBUgNrPdon7QEy_6md_5rw0=+-KOV90Q@mail.gmail.com>
	<21703.42771.678057.885871@stat.math.ethz.ch>
Message-ID: <CABdHhvE7bZnNq7R6C-dZS43hhwKMvWAiV5p7eHgrb612NUxPJg@mail.gmail.com>

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/



[Rd] Inspect a "delayed" assigned whose value throws an error?
Hadley Wickham