load_all()
loads a package. It roughly simulates what happens
when a package is installed and loaded with library()
, without
having to first install the package. It:
Loads all data files in
data/
. Seeload_data()
for more details.Sources all R files in the R directory, storing results in environment that behaves like a regular package namespace. See
load_code()
for more details.Adds a shim from
system.file()
toshim_system.file()
in the imports environment of the package. This ensures thatsystem.file()
works with both development and installed packages despite their differing directory structures.Adds shims from
help()
and?
toshim_help()
andshim_question()
to make it easier to preview development documentation.Compiles any C, C++, or Fortran code in the
src/
directory and connects the generated DLL into R. Seepkgbuild::compile_dll()
for more details.Loads any compiled translations in
inst/po
.Runs
.onAttach()
,.onLoad()
and.onUnload()
functions at the correct times.If you use testthat, will load all test helpers so you can access them interactively. devtools sets the
DEVTOOLS_LOAD
environment variable to"true"
to let you check whether the helpers are run during package loading.
is_loading()
returns TRUE
when it is called while load_all()
is running. This may be useful e.g. in .onLoad
hooks.
Usage
load_all(
path = ".",
reset = TRUE,
compile = NA,
attach = TRUE,
export_all = TRUE,
export_imports = export_all,
helpers = TRUE,
attach_testthat = uses_testthat(path),
quiet = NULL,
recompile = FALSE,
warn_conflicts = TRUE
)
is_loading(pkg = NULL)
Arguments
- path
Path to a package, or within a package.
- reset
clear package environment and reset file cache before loading any pieces of the package. This largely equivalent to running
unload()
, however the old namespaces are not completely removed and no.onUnload()
hooks are called. Usereset = FALSE
may be faster for large code bases, but is a significantly less accurate approximation.- compile
If
TRUE
always recompiles the package; ifNA
recompiles if needed (as determined bypkgbuild::needs_compile()
); ifFALSE
, never recompiles.- attach
Whether to attach a package environment to the search path. If
FALSE
load_all()
behaves likeloadNamespace()
. IfTRUE
(the default), it behaves likelibrary()
. IfFALSE
, theexport_all
,export_imports
, andhelpers
arguments have no effect.- export_all
If
TRUE
(the default), export all objects. IfFALSE
, export only the objects that are listed as exports in the NAMESPACE file.- export_imports
If
TRUE
(the default), export all objects that are imported by the package. IfFALSE
export only objects defined in the package.- helpers
if
TRUE
loads testthat test helpers.- attach_testthat
If
TRUE
, attach testthat to the search path, which more closely mimics the environment within test files.- quiet
if
TRUE
suppresses output from this function.- recompile
DEPRECATED. force a recompile of DLL from source code, if present. This is equivalent to running
pkgbuild::clean_dll()
beforeload_all()
- warn_conflicts
If
TRUE
, issues a warning if a function in the global environment masks a function in the package. This can happen when you accidentally source a.R
file, rather than usingload_all()
, or if you define a function directly in the R console. This is frustrating to debug, as it feels like the changes you make to the package source aren't having the expected effect.- pkg
If supplied,
is_loading()
only returnsTRUE
if the package being loaded ispkg
.
Differences to regular loading
load_all()
tries its best to reproduce the behaviour of
loadNamespace()
and library()
. However it deviates from normal
package loading in several ways.
load_all()
doesn't install the package to a library, sosystem.file()
doesn't work. pkgload fixes this for the package itself installing a shim,shim_system.file()
. However, this shim is not visible to third party packages, so they will fail if they attempt to find files within your package. One potential workaround is to usefs::path_package()
instead ofsystem.file()
, since that understands the mechanisms that devtools uses to load packages.load_all()
loads all packages referenced inImports
at load time, butloadNamespace()
andlibrary()
only load package dependencies as they are needed.load_all()
copies all objects (not just the ones listed as exports) into the package environment. This is useful during development because it makes internal objects easy to access. To export only the objects listed as exports, useexport_all = FALSE
. This more closely simulates behavior when loading an installed package withlibrary()
, and can be useful for checking for missing exports.
Examples
if (FALSE) {
# Load the package in the current directory
load_all("./")
# Running again loads changed files
load_all("./")
# With reset=TRUE, unload and reload the package for a clean start
load_all("./", TRUE)
# With export_all=FALSE, only objects listed as exports in NAMESPACE
# are exported
load_all("./", export_all = FALSE)
}