[Rd] Something strange in "?assign"? (PR#433)

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
11 Feb 2000 13:32:22 +0100


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._