You can do this:
a <- F
f1 <- function() a
f2 <- function() {
a <- T
environment(f1) <- new.env()
eval(f1())
}
f2()
# [1] TRUE
Though I wouldn't encourage it. What we've done here is changed the environment of f1
to be one which has for enclosure f2
's environment, which means f1
will have access to f2
s variables through "lexical" scoping (well, faux-lexical here b/c we short circuited it).
Generally, as Roman suggests, you should explicitly pass arguments to functions as otherwise you can quickly run into trouble.