Codettools Query

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Codettools Query

Saptarshi
Hello,

The following code

moo <- function(a=1){ x=1; x=x+y}
funs <- new.env()
enter <- function(type, v, e, w){
  assign(v, TRUE, funs)
}
library(codetools)
collectUsage(moo, enterGlobal = enter)


adds + to the environment funs i.e.

funs: "=" "{" "+" "y"

How can i ignore variables which are present in base, utils, stat
environments from being added (equivalently, symbols present in R when R is
started)

I tried



funs <- new.env()
enter <- function(type, v, e, w){
  if(codetools:::isBaseVar(v, w$env) || codetools:::isStatsVar(v, w$env)
     || codetools:::isUtilsVar(v, w$env) || v == "Quote")
    return()
  assign(v, TRUE, funs)
}

library(codetools)
collectUsage(moo, enterGlobal = enter)

but this threw

Error in exists(v, envir = e, inherits = FALSE, mode = "function") :
  invalid 'envir' argument

Cheers
Saptarshi

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.