hadley / strict

Make R a little bit stricter
235 stars 10 forks source link

Force local environment for variables inside functions #17

Closed juuussi closed 7 years ago

juuussi commented 7 years ago

Would be great to have an error when trying to access variables outside of the local scope from inside a function, unless explicitly specified. I personally think this is one of the most useful checks in Perl strict, and something that causes a lot of problems for especially beginner R coders.

hadley commented 7 years ago

Unfortunately there's no practical way to do that. Take this simple function:

f <- function(x, y) {
  x + y
}

It accesses two variables from outside the local scope: { and +.