For example, if ran the script.A
:
library(ggplot2)
a <- 12
and then script.B
library(ggplot2)
b <- runif(100)
qplot(b)
I'd be able to tell that script.A
did not actually make use of ggplot2
, whereas script.B
did.
Load the library normally and trace all functions in the package environment (and in the namespace). I'll use a small helper function to do 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 is needed to ensure that calls such as data.table::xxx()
also get 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 that the code was interrupted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With