Philippe Grosjean
2012-Apr-29 07:30 UTC
[Rd] A doubt about substitute() after delayedAssign()
Hello,
?delayedAssign presents substitute() as a way to look at the expression
in the promise. However,
msg <- "old"
delayedAssign("x", msg)
msg <- "new!"
x #- new!
substitute(x) #- x (was 'msg' ?)
Here, we just got 'x'... shouldn't we got 'msg'?
Same result when the promise is not evaluated yet:
delayedAssign("x", msg)
substitute(x)
In a function, that works:
foo <- function (x = msg) substitute(x)
foo()
Did I misunderstood something? It seems to me that substitute() does not
behaves as documented for promises created using delayedAssign().
Best,
Philippe
--
..............................................<?}))><........
) ) ) ) )
( ( ( ( ( Prof. Philippe Grosjean
) ) ) ) )
( ( ( ( ( Numerical Ecology of Aquatic Systems
) ) ) ) ) Mons University, Belgium
( ( ( ( (
..............................................................
Duncan Murdoch
2012-Apr-29 11:50 UTC
[Rd] A doubt about substitute() after delayedAssign()
On 12-04-29 3:30 AM, Philippe Grosjean wrote:
> Hello,
>
> ?delayedAssign presents substitute() as a way to look at the expression
> in the promise. However,
>
> msg<- "old"
> delayedAssign("x", msg)
> msg<- "new!"
> x #- new!
> substitute(x) #- x (was 'msg' ?)
>
> Here, we just got 'x'... shouldn't we got 'msg'?
>
> Same result when the promise is not evaluated yet:
>
> delayedAssign("x", msg)
> substitute(x)
>
> In a function, that works:
>
> foo<- function (x = msg) substitute(x)
> foo()
>
> Did I misunderstood something? It seems to me that substitute() does not
> behaves as documented for promises created using delayedAssign().
I don't think this is well documented, but substitute() doesn't act the
same when its "env" argument is the global environment. So this works
the way you'd expect:
e <- new.env()
msg <- "old"
delayedAssign("x", msg, assign=e)
msg <- "new"
e$x
substitute(x, e)
I forget what the motivation was for special-casing globalenv().
Duncan Murdoch
Maybe Matching Threads
- Substitute / delayedAssign (was: Substitute unaware when promise objects are evaluated)
- question on docs for delayedAssign and substitute
- Lazy loading... advices
- [Fwd: Re: How to activate the R commands in SciViews]
- Additional arguments in S3 method produces a warning