[R] print and execute functions in a package namespace
Hadley Wickham
h.wickham at gmail.com
Tue Oct 30 14:52:03 CET 2012
> But I need to work with the names of the figure functions instead, something
> like
>
> figlist <- paste0("fig", 1:3)
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
--
RStudio / Rice University
http://had.co.nz/
More information about the R-help
mailing list