Is there an easy way to tell if an R script made use of any function in a loaded package? -


for example, if ran script.a:

 library(ggplot2)  <- 12  

and script.b

library(ggplot2) b <- runif(100) qplot(b)  

i'd able tell script.a did not make use of ggplot2, whereas script.b did.

load library , trace functions in package environment (and in namespace). i'll use small helper function this:

trap_funs <- function(env) {     f <- sapply(as.list(env, all.names=true), is.function)     for( n in names(f)[f] ) trace(n, bquote(stop(paste("script called function", .(n)))), where=env) } 

example:

library(data.table) trap_funs(as.environment("package:data.table")) trap_funs(asnamespace("data.table")) 

this second statement needed ensure calls such data.table::xxx() trapped.

example:

> as.data.table(mtcars) tracing as.data.table(mtcars) on entry  error in eval(expr, envir, enclos) : script called function as.data.table 

note code interrupted.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo