How to access variables defined outside the scope of a function.
foo <- "bar"
f <- function(){
print(foo)
}
I should be able to print "bar"
You can use get()
:
foo <- "bar"
test <- function(){
print(get("foo", envir = .GlobalEnv))
}
> test()
[1] "bar"