brought up on S-Plus, where assignment -
is guaranteed to assign to frame 1.
HTH
-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
Sent: 18 February 2004 04:19
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: [R] pass by reference -- how to do it
Security
: [R] pass by reference -- how to do it
For the record, be careful: - does not necessarily assign to
the global environment. In R ` x - value` assigns `value` to
the first instance of `x` it can find using lexical scoping. Only if it
doesn't find any such variable, it will indeed create an `x
PROTECTED];
[EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: [R] pass by reference -- how to do it
Security Warning:
If you are not sure an attachment is safe to open please contact
Andy on x234. There are 0 attachments with this message
One needs to be more careful with - in R than in S-PLUS, because of the
scoping rule difference. ?- says:
The operators '-' and '-' cause a search to made through the
environment for an existing definition of the variable being
assigned. If such a variable is found then its value
If you don't mind NOT passing your arrays at all then you
can do this:
f - function() a[1] - a[1] + 1
a - 1:5
f() # increments first element of a by 1
a # c(2,2,3,4,5)
The - causes the expression to take place in the global
environment.
If you want to actually pass your arrays by