Load All Package Code
Description
Sources all R files in a package for interactive development, without a
full install. By default the sourced environment is attached to the search
path (like devtools::load_all()), so the package's functions are
immediately callable in the session. Help pages are not available this way;
use install() or reload() if you need ?topic docs.
Usage
load_all(path = ".", env = new.env(parent = globalenv()), quiet = TRUE,
attach = TRUE)
load_all(path = ".", env = new.env(parent = globalenv()), quiet = TRUE,
attach = TRUE)
Arguments
path |
Path to package root directory.
|
env |
Environment to source files into. Defaults to a fresh
environment whose parent is the global environment.
|
quiet |
Logical. Suppress file sourcing messages? Default TRUE.
|
attach |
Logical. Attach the sourced environment to the search path as
package:<name> so its functions are callable directly? Default
TRUE. A previous attachment of the same package is replaced. Set FALSE to
only return the environment without touching the search path. Kept last in
the argument list so positional calls from earlier versions still work.
|
Value
The environment into which files were sourced (invisibly).
See Also
kitten for scaffolding a new package.
Examples
# Scaffold a throwaway package in tempdir() and source its R/ files.
pkg <- file.path(tempdir(), "loadpkg")
dir.create(file.path(pkg, "R"), recursive = TRUE, showWarnings = FALSE)
writeLines(c(
"Package: loadpkg",
"Title: Example",
"Version: 0.0.1",
"Authors@R: person('A', 'B', email = '[email protected]', role = c('aut','cre'))",
"Description: Example.",
"License: GPL-3"
), file.path(pkg, "DESCRIPTION"))
writeLines("add <- function(x, y) x + y", file.path(pkg, "R", "add.R"))
# attach = FALSE returns the environment without touching the search path.
e <- load_all(pkg, attach = FALSE)
e$add(2, 3)
unlink(pkg, recursive = TRUE)
pkg <- file.path(tempdir(), "loadpkg")
dir.create(file.path(pkg, "R"), recursive = TRUE, showWarnings = FALSE)
writeLines(c(
"Package: loadpkg",
"Title: Example",
"Version: 0.0.1",
"Authors@R: person('A', 'B', email = '[email protected]', role = c('aut','cre'))",
"Description: Example.",
"License: GPL-3"
), file.path(pkg, "DESCRIPTION"))
writeLines("add <- function(x, y) x + y", file.path(pkg, "R", "add.R"))
e <- load_all(pkg, attach = FALSE)
e$add(2, 3)
unlink(pkg, recursive = TRUE)