Writing R codes to verify another R code will be difficult. You need to find a way to determine which bits of code were variable declarations, and then try to find out if they were already declared inside the function. EDIT: The previous statement would be true, but, as Aniko noted, the hard work was already done in the codetools package.
One related thing that may be useful to you is to make the variable be taken from the function itself (and not from the environment).
This modified version of your function always fails because n not declared.
aha <- function(p) { n <- get("n", inherits=FALSE) return(p+n) }
Richie cotton
source share