View source: R/check_data_prep_function.R
runsusingpackagesonly | R Documentation |
Check that function runs using objects only in its argument list or imported from currently loaded packages
runsusingpackagesonly(fun, args, erroronfalse = TRUE)
fun |
The function to check |
args |
An argument list to pass to |
TRUE if the functions runs in the parent environment of the global environment (an environment with only packages) with arguments attached, which means the function runs when it can't access the interactively defined objects. Or FALSE if arguments are missing, the function tries to access an object in the global environment (and not in the parent environment), or if there is some other problem with the function executing. In this case a warning is given. This warning contains the error condition that created the failure.
myfun <- function(B, sd){ out <- (B - cmns) * sd return(out) } runsusingpackagesonly(myfun, args = list(sd = 3)) #returns FALSE B <- matrix(rnorm(4 * 3), nrow = 3) runsusingpackagesonly(myfun, args = list(sd = 3, B = B)) #returns FALSE cmns <- colMeans(B) runsusingpackagesonly(myfun, args = list(sd = 3, B = B)) #returns FALSE too - myfun run such that it can't see globalenv() myfun2 <- function(B, sd, cmns){ out <- (B - cmns) * sd return(out) } runsusingpackagesonly(myfun2, args = list(sd = 3, B = B, cmns = cmns)) # TRUE, which is correct! :)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.