Henrik Bengtsson
2010-Jun-01 18:41 UTC
[Rd] codetools: Suggestion to detect potentially unassigned variables
This is just a note/wishlist/for the record:
With
foo1 <- function() {
res;
}
foo2 <- function() {
for (i in c()) res <- 1;
res;
}
foo3 <- function() {
while (FALSE) res <- 1;
res;
}
foo4 <- function() {
if (FALSE) res <- 1;
res;
}
we get:
> foo1()
Error in foo1() : object 'res' not found> foo2()
Error in foo2() : object 'res' not found> foo3()
Error in foo3() : object 'res' not found> foo4()
Error in foo4() : object 'res' not found
Running R CMD check on R v2.11.1pat we get:
* checking R code for possible problems ... NOTE
foo1: no visible binding for global variable 'res'
An improvement would be to also report that:
foo2: variable 'res' may not be assigned
foo3: variable 'res' may not be assigned
foo4: variable 'res' may not be assigned
/Henrik
