[R] variable scope

David Brahm brahm at alum.mit.edu
Mon Aug 5 16:41:49 CEST 2002


VBMorozov at lbl.gov wrote:
> I would like to pass variables to a function in R in "by reference"...

Just in case the ensuing discussion got too esoteric, here's one simple answer:

R> x <- 1:10
R> MyFunc <- function(x, zz) assign(deparse(substitute(zz)), sum(x), 1)
R> MyFunc(x,y)
R> y
   [1] 55
-- 
                           -- David Brahm (brahm at alum.mit.edu) (former LBL guy)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list