Change
delayedAssign("x", msg)
to
delayedAssign("x", { cat("Assigning 'msg' to
'x' now\n") ; msg })
and you will see the message when the delayed assignment is triggered.
You could add print(sys.calls()) to that to see the call stack if it isn't
obvious.
> msg <- "old"
> delayedAssign("x", { cat("Assigning 'msg' to
'x' now\n") ; print(sys.calls()) ; msg })
> f <- function(p) paste(x, p)
> f("qwerty")
Assigning 'msg' to 'x' now
[[1]]
f("qwerty")
[[2]]
paste(x, p)
[[3]]
print(sys.calls())
[1] "old qwerty"> x
[1] "old"
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at
r-project.org] On Behalf
> Of Gang Peng
> Sent: Wednesday, August 14, 2013 6:12 PM
> To: r-help at r-project.org
> Subject: [R] A question about using delayedAssign
>
> I run the examples in delayedAssign:
>
> msg <- "old"
> delayedAssign("x", msg)
> msg <- "new!"
> x
>
> If I run these four commands together, x is "new". If I run the
first two
> commands first and then run the last two commands, x is "old".
>
> I just cannot figure out why.
>
> Thanks.
> Gang
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.