loads or reloads if needed a source package, taking care of its dependencies
Source:R/pkg_load.R
pkg_load.RdN.B: the defaults are different from devtools::load_all(): the helpers are not loaded, only
the functions tagged as exported are actually exported. The intended goal is to make it as similar
to the behaviour of the R loaders.
Usage
pkg_load(
pkgid,
src_pkgs = get_srcpkgs(),
attach = TRUE,
suggests = FALSE,
roxygen = TRUE,
helpers = FALSE,
export_all = FALSE,
quiet = FALSE,
dry_run = FALSE,
...
)Arguments
- pkgid
a package name, path or package object
- src_pkgs
a collection of source packages as a
srckgsobject.- attach
Whether to attach a package environment to the search path. If
FALSEload_all()behaves likeloadNamespace(). IfTRUE(the default), it behaves likelibrary(). IfFALSE, theexport_all,export_imports, andhelpersarguments have no effect.- suggests
whether to load suggested packages. if TRUE, the suggested are processed like imports
- roxygen
whether to automatically roxygenise packages (if needed)
- helpers
if
TRUEloads testthat test helpers.- export_all
If
TRUE(the default), export all objects. IfFALSE, export only the objects that are listed as exports in the NAMESPACE file.- quiet
whether to be quiet/silent
- dry_run
whether not to actually execute any action having side-effects
- ...
Arguments passed on to
devtools::load_allpathPath to a package, or within a package.
resetThis is no longer supported because preserving the namespace requires unlocking its environment, which is no longer possible in recent versions of R.
recompileDEPRECATED. force a recompile of DLL from source code, if present. This is equivalent to running
pkgbuild::clean_dll()beforeload_all()
Details
This the workhorse function of the package, called by library() and loadNamespace()
when hacked (cf hack_r_loaders().
This function will check that all dependent packages are up-to-date, and document and reload them as needed.
To be able to properly load a package, its dependent source packages must be loaded in proper order. i.e. if A–>B–>C, the load order must be C, B, A
Examples
pkg <- setup_and_get_dummy_srcpkg()
# load and attach a package
pkg_load(pkg)
#> executing unload on dummy.srcpkg
#> executing load on dummy.srcpkg
#> ℹ Updating dummy.srcpkg documentation
#> First time using roxygen2. Upgrading automatically...
#> ℹ Setting RoxygenNote to "7.3.3"
#> ℹ Loading dummy.srcpkg
#> Writing NAMESPACE
#> ℹ Loading dummy.srcpkg
# just load, do not attach it (~ loadNamespace())
pkg_unload(pkg)
#> executing unload on dummy.srcpkg
pkg_load(pkg, attach = FALSE)
#> executing load on dummy.srcpkg
#> ℹ Loading dummy.srcpkg
# do some changes, to a source package or any of its depencies or dependents
pkg_unload(pkg)
#> executing unload on dummy.srcpkg
plan <- pkg_load(pkg, dry_run = TRUE)
# then you can inspect the plan actions