J.C.Rougier@durham.ac.uk
2000-Feb-11 12:22 UTC
[Rd] Something strange in "?assign"? (PR#433)
According to the assign helpfile (0.90.1) the "assign" function is
function (x, value, pos = -1, envir = sys.frame(sys.parent()),
inherits = FALSE, immediate = TRUE)
which is not quite the implementation, which is
function (x, value, pos = -1, envir = pos.to.env(pos), inherits = FALSE,
immediate = TRUE)
This seems to have the following interesting effect.
"short.fun" <- function() {make(); ls()}
"make" <- function() assign("x", 3, envir =
sys.frame(sys.parent()))
short.fun() # gives an x as I would expect
"make" <- function() assign("x", 3)
short.fun() # now there's nothing here!
But since I have simply duplicated the default value, according to the
help file, I would expect these two "make" functions to behave
identically. Is this to be expected, and if not, is this because the
definition of "assign" is slightly different to that in the help file?
Many thanks, Jonathan.
Jonathan Rougier Science Laboratories
Department of Mathematical Sciences South Road
University of Durham Durham DH1 3LE
http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:
r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
J.C.Rougier@durham.ac.uk writes:> According to the assign helpfile (0.90.1) the "assign" function is > > function (x, value, pos = -1, envir = sys.frame(sys.parent()), > inherits = FALSE, immediate = TRUE) > > which is not quite the implementation, which is > > function (x, value, pos = -1, envir = pos.to.env(pos), inherits = FALSE, > immediate = TRUE)OK, that's a bug, in the documentation. However, it is not a bug that sys.frame(sys.parent()) gives different results as a default argument and as a supplied one. One is evaluated in the function, the other in the caller!> "short.fun" <- function() {make(); ls()} > "make" <- function() assign("x", 3, envir = sys.frame(sys.parent())) > > short.fun() # gives an x as I would expect > > "make" <- function() assign("x", 3) > > short.fun() # now there's nothing here!Try changing make() to function() {assign("x", 3);print(ls())} -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._