Possible Duplicate:
Limiting variable scope
One of the easiest errors for me to slip into is having a function access a variable that is in the global environment as opposed to the local environment. During development, this might happen when I change the name of a variable and forget to rm
the old one--then fail to update a function to make it access the new one.
Is there a way to have R return an error or warning whenever it automatically grabs a variable from higher up in the tree? It seems like this would be easier now that R supports compiled code....
Here's a quickie example of what I'd like to return an error/warning:
x <- 5
f <- function(y) {
z <- y + x
z
}
f(3) #will return 8