From hb at stat.berkeley.edu  Tue Jun  1 20:41:38 2010
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Tue, 1 Jun 2010 20:41:38 +0200
Subject: [Rd] codetools: Suggestion to detect potentially unassigned
	variables
Message-ID: <AANLkTik_LV9G2cpHIyfcBq2RJrrtg3YUYyJ_jYEX5wUV@mail.gmail.com>

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



[Rd] codetools: Suggestion to detect potentially unassigned variables
Henrik Bengtsson