Title: | R Source Packages Manager |
---|---|
Description: | Manage a collection/library of R source packages. Discover, document, load, test source packages. Enable to use those packages as if they were actually installed. Quickly reload only what is needed on source code change. Run tests and checks in parallel. |
Authors: | Karl Forner [aut, cre, cph] |
Maintainer: | Karl Forner <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.1 |
Built: | 2024-11-20 04:36:30 UTC |
Source: | https://github.com/kforner/srcpkgs |
Manage a collection/library of R source packages. Discover, document, load, test source packages. Enable to use those packages as if they were actually installed. Quickly reload only what is needed on source code change. Run tests and checks in parallel.
srcpkgs
main objective is to ease development on any project
that uses a collection of R source packages (a library).
It is able to figure out which dependencies are source packages, and is able
to quickly detect changes in any of the used source packages.
Maintainer: Karl Forner [email protected] [copyright holder]
Useful links:
N.B: the hidden files and directories are ignored.
In general, this function is not used directly, instead you should use get_srcpkgs()
find_srcpkgs( root = get_project_root(), srcpkgs_paths = find_srcpkgs_paths(root, prune = prune), prune = TRUE )
find_srcpkgs( root = get_project_root(), srcpkgs_paths = find_srcpkgs_paths(root, prune = prune), prune = TRUE )
root |
directory from where to search for source packages |
srcpkgs_paths |
paths to the source packages folders |
prune |
whether to report packages contained inside another package (e.g. in tests/) |
a "srcpkgs" object (or NULL if none found), a named list of "srcpkg" objects, that essentially are devtools "package" objects. The list is named after the package names.
find_srcpkgs('.')
find_srcpkgs('.')
The first call to this function will trigger the initialization of the package ((cf reset()
).
Since it is used by mostly all user-facing load-related functions, this enables a runtime initialization,
as opposed to a load-time initialization. So for example
you may load srcpkgs
, then change the current directory to your project.
Then the first load will setup the settings.
get_srcpkgs()
get_srcpkgs()
For optimization, the paths to discovered source packages are cached (cf reset()
and settings()
.
This function will reparse the DESCRIPTION for any change.
If you add or delete a source package, you must reset the source package paths using reset()
This function is useful for troubleshooting, to understand what are the source packages discovered
and managed by srcpkgs
the source packages as a "scrpkgs" object, cf find_srcpkgs()
, or NULL if none
pkgs <- get_srcpkgs() print(pkgs)
pkgs <- get_srcpkgs() print(pkgs)
hacks library()
and loadNamespace()
using the base R tracer function trace()
.
library(pkg)
will basically call pkg_load(pkg)
if the source package pkg
is managed by srcpkgs
hack_r_loaders()
hack_r_loaders()
N.B: usually you do not need to call that function explicitly. The function is reentrant.
no return value, called for side-effects
At package startup (actually .OnAttach()
), hack_r_loaders()
will be automatically called to hack
the R loaders, UNLESS this is inhibited via the option srcpkgs.inhibit_r_loaders_hack
or the
environment variable SRCPKGS.INHIBIT_R_LOADERS_HACK
. You may set any value like TRUE, "TRUE", 1 or "1".
# hack library hack_r_loaders() # unhack unhack_r_loaders() # prevent automatic hacking when srcpkgs is loaded options(srcpkgs.inhibit_r_loaders_hack=TRUE) # or Sys.setenv(SRCPKGS.INHIBIT_R_LOADERS_HACK="1") library(srcpkgs)
# hack library hack_r_loaders() # unhack unhack_r_loaders() # prevent automatic hacking when srcpkgs is loaded options(srcpkgs.inhibit_r_loaders_hack=TRUE) # or Sys.setenv(SRCPKGS.INHIBIT_R_LOADERS_HACK="1") library(srcpkgs)
N.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.
pkg_load( pkgid, src_pkgs = get_srcpkgs(), attach = TRUE, suggests = FALSE, roxygen = TRUE, helpers = FALSE, export_all = FALSE, quiet = FALSE, dry_run = FALSE, ... )
pkg_load( pkgid, src_pkgs = get_srcpkgs(), attach = TRUE, suggests = FALSE, roxygen = TRUE, helpers = FALSE, export_all = FALSE, quiet = FALSE, dry_run = FALSE, ... )
pkgid |
a package name, path or object |
src_pkgs |
a collection of source packages as a |
attach |
Whether to attach a package environment to the search
path. If |
suggests |
whether to load suggested packages. if TRUE, the suggested are processed like imports |
roxygen |
whether to automatically roxygenise packages (if needed) |
helpers |
if |
export_all |
If |
quiet |
whether to be quiet/silent |
dry_run |
whether not to actually execute any action having side-effects |
... |
Arguments passed on to
|
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
the load plan as a data frame, or NULL if there is nothing to do.
## Not run: # N.B: This example is wrapped in \dontrun as it cannot be executed since it requires # a source package to load. # load and attach a package pkg_load('mypkg') # just load, do not attach it (~ loadNamespace()) pkg_load('mypkg', attach = FALSE) # do some changes, to a source package or any of its depencies or dependents plan <- pkg_load('mypkg', dry_run = TRUE) # then you can inspect the plan actions ## End(Not run)
## Not run: # N.B: This example is wrapped in \dontrun as it cannot be executed since it requires # a source package to load. # load and attach a package pkg_load('mypkg') # just load, do not attach it (~ loadNamespace()) pkg_load('mypkg', attach = FALSE) # do some changes, to a source package or any of its depencies or dependents plan <- pkg_load('mypkg', dry_run = TRUE) # then you can inspect the plan actions ## End(Not run)
To be able to unload properly a package, all the packages that depend even indirectly on it should be unloaded first.
pkg_unload( pkg_or_name, src_pkgs = get_srcpkgs(), dry_run = FALSE, loaded = loadedNamespaces(), quiet = FALSE )
pkg_unload( pkg_or_name, src_pkgs = get_srcpkgs(), dry_run = FALSE, loaded = loadedNamespaces(), quiet = FALSE )
pkg_or_name |
a package name or object ("package" or "srcpkg") |
src_pkgs |
a collection of source packages as a |
dry_run |
whether not to actually execute any action having side-effects |
loaded |
the loaded packages, useful for testing. |
quiet |
whether to be quiet/silent |
N.B: this function also works for non source packages.
a data frame of the unloaded package names, and whether they were attached, invisibly or NULL if the package is not loaded
plan <- pkg_unload('mypkg')
plan <- pkg_unload('mypkg')
srcpkgs
settingsWith this function, you can reset or set precisely the settings.
reset(root = find_project_root(), srcpkgs_paths = find_srcpkgs_paths(root))
reset(root = find_project_root(), srcpkgs_paths = find_srcpkgs_paths(root))
root |
directory from where to search for source packages |
srcpkgs_paths |
paths to the source packages folders |
the settings (cf settings()
) invisibly
# reset to appropriate defaults based on your current directory reset() # explictly set the project root reset(root = tempdir()) # explictly set the source package paths (very unlikely) reset(srcpkgs_paths = c('pkgs/mypkg1', 'pkgs/mypkg2'))
# reset to appropriate defaults based on your current directory reset() # explictly set the project root reset(root = tempdir()) # explictly set the source package paths (very unlikely) reset(srcpkgs_paths = c('pkgs/mypkg1', 'pkgs/mypkg2'))
srcpkgs
informs about the settings currently used by srcpkgs
settings()
settings()
a named list of:
initialized: whether the settings are initialized (as triggered by get_srcpkgs()
)
root: the project root
srcpkgs_paths: the paths of the source packages to manage
hack_r_loaders_installed: whether the R loaders are hacked
hack_r_loaders_enabled: whether the R loaded hack is in action (internal use0
The function is reentrant.
unhack_r_loaders()
unhack_r_loaders()
no return value, called for side-effects