r-lib / lintr

Static Code Analysis for R
https://lintr.r-lib.org
Other
1.19k stars 185 forks source link

lintr does not check variable scope #330

Closed azoimide closed 5 years ago

azoimide commented 6 years ago

Linting this code should yield a warning since the function uses a variable that is neither a parameter nor local:

a <- 1
f <- function() {
    return(a + 1)
}
hongooi73 commented 5 years ago

This is debatable, given that lexical scope is a feature, not a bug in R:

function(lst)
{
    y <- 42
    lapply(lst, function(x) x + y)
}

Here, the inner function will find y in the scope of the outer function without requiring it as an explicit argument.

jimhester commented 5 years ago

Agreed, lexical scoping is used a great deal in R code, I don't think we should have a linter for this.