The last two lines of example(delayedAssign) give this:> e <- (function(x, y = 1, z) environment())(1+2, "y", {cat(" HO! "); pi+2}) > (le <- as.list(e)) # evaluates the promises$x <promise: 0x032b31f8> $y <promise: 0x032b3230> $z <promise: 0x032b3268> which contrary to the comment appears unevaluated. Is the comment wrong or is it supposed to return an evaluated result but doesn't?> R.version.string # Vista[1] "R version 2.6.0 alpha (2007-09-06 r42791)"
Gabor Grothendieck wrote:> The last two lines of example(delayedAssign) give this: > > >> e <- (function(x, y = 1, z) environment())(1+2, "y", {cat(" HO! "); pi+2}) >> (le <- as.list(e)) # evaluates the promises >> > $x > <promise: 0x032b31f8> > $y > <promise: 0x032b3230> > $z > <promise: 0x032b3268> > > which contrary to the comment appears unevaluated. Is the comment > wrong or is it supposed to return an evaluated result but doesn't? > >My guess would be that the behaviour is unintended. It should be harder than that to get promises visible at the user level. Luke?>> R.version.string # Vista >> > [1] "R version 2.6.0 alpha (2007-09-06 r42791)" > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Also note that earlier in the same example we have:> msg <- "old" > delayedAssign("x", msg) > msg <- "new!" > x #- new![1] "new!"> substitute(x) #- msgx> R.version.string # Vista[1] "R version 2.6.0 alpha (2007-09-06 r42791)" That is substitute(x) gives x, not msg. On 9/19/07, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> The last two lines of example(delayedAssign) give this: > > > e <- (function(x, y = 1, z) environment())(1+2, "y", {cat(" HO! "); pi+2}) > > (le <- as.list(e)) # evaluates the promises > $x > <promise: 0x032b31f8> > $y > <promise: 0x032b3230> > $z > <promise: 0x032b3268> > > which contrary to the comment appears unevaluated. Is the comment > wrong or is it supposed to return an evaluated result but doesn't? > > > R.version.string # Vista > [1] "R version 2.6.0 alpha (2007-09-06 r42791)" >
I thought that perhaps the behavior in the previous post, while inconsistent with the documentation, was not all that harmful but I think its related to the following which is a potentially serious bug. z is a list with a single numeric component, as the dput output verifies, yet we cannot compare its first element to 7 without getting an error message. Later on we see that its because it thinks that z[[1]] is of type "promise" and even force(z[[1]]) is of type "promise".> f <- function(x) environment() > z <- as.list(f(7)) > dput(z)structure(list(x = 7), .Names = "x")> z[[1]] == 7Error in z[[1]] == 7 : comparison (1) is possible only for atomic and list types> force(z[[1]]) == 7Error in force(z[[1]]) == 7 : comparison (1) is possible only for atomic and list types> > typeof(z)[1] "list"> typeof(z[[1]])[1] "promise"> typeof(force(z[[1]]))[1] "promise"> R.version.string # Vista[1] "R version 2.6.0 beta (2007-09-23 r42958)" On 9/19/07, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> The last two lines of example(delayedAssign) give this: > > > e <- (function(x, y = 1, z) environment())(1+2, "y", {cat(" HO! "); pi+2}) > > (le <- as.list(e)) # evaluates the promises > $x > <promise: 0x032b31f8> > $y > <promise: 0x032b3230> > $z > <promise: 0x032b3268> > > which contrary to the comment appears unevaluated. Is the comment > wrong or is it supposed to return an evaluated result but doesn't? > > > R.version.string # Vista > [1] "R version 2.6.0 alpha (2007-09-06 r42791)" >