David Brahm <brahm at alum.mit.edu> wrote:
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
Still less esoteric is
MyFunc <- function(x,zz) zz <<- sum(x) MyFunc(1:10,y) y
[1] 55 Although I don't know if this is a good general solution to `passing by reference' (BTW it behaves differently in S+
MyFunc <- function(x,zz) zz <<- sum(x) MyFunc(1:10,y)
[1] 55
y
[1] 1 2 3 4 5 6 7 8 9 10 )
Steve Wisdom http://208.202.87.68/subsidiaries/subsdeep.asp -------------------------------------------------- DISCLAIMER This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify me and permanently delete the original and any copy of any e-mail and any printout thereof. E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. NOTICE regarding privacy and confidentiality Knight Trading Group may, at its discretion, monitor and review the content of all e-mail communications. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._