0

In

Global variables in R

we have code

a <- "old"
test <- function () {
   assign("a", "new", envir = .GlobalEnv)
}
test()
a  # display the new value

If we remove the 'a <- "old"' command, and run with a clear workspace, we see that test() not only modifies the value of variable "a", test() also DEFINES "a" for the program.

0 Answers0