[R] Communicating from one function to another
Alberto Monteiro
albmont at centroin.com.br
Mon Nov 26 19:25:29 CET 2007
Thomas L Jones wrote:
>
> My question is a seemingly simple one. I have a bunch of user-
> defined functions which compute such-and-such objects. I want to be
> able to define a variable in a particular function, then make use of
> it later, perhaps in a different function, without necessarily
> having to move it around in argument lists. In the C community, it
> would be called a "global" variable.
>
Global variables in R are used with <<- instead of <-.
For example:
x <- 1
y <- 1
f <- function() {
x <- 2
y <<- 2
}
f()
will turn y to 2 but will not change x.
Alberto Monteiro
More information about the R-help
mailing list