Skip to content
Prev 309354 / 398506 Next

print and execute functions in a package namespace

Are the functions exported or internal?

# Use for internal functions
pkg <- asNamespace("mypackage")
# Use for exported functions:
pkg <- "package:mypackage"

# Find functions matching a pattern:
figfuns <- grep("fun.*", ls(pkg), value = TRUE)

# Convert names into functions
funs <- lapply(fig, get, envir = pkg)

onefig2 <- function(fig) {
    cat("Figure:", fig, "\n")
    print(body(fig))
    fig()
}
lapply(funs, onefig2)

Hadley