{dir} allows you to store your code in a nested folder structure, rather than solely in the “R” folder.
To do so you might for instance have in your “zzz.R” file:
.onLoad <- function(libname, pkgname) {
if (Sys.getenv("DEVTOOLS_LOAD") == pkgname) dir::add("new_top_level_folder", "maybe_another_one")
}
Then use devtools::load_all()
as you would normally, now it will load
also the code from your added folders (recursively into nested folders
by default).
devtools::load_all()
will now also take care of the documentation so
no need to call devtools::document()
(and if you do, it will delete
some “.Rd” files, we found no way around it).
Files and folders starting with “_” in your added folders will be ignored by the process.
dir:add()
will never be called by your end users.
Install with:
pak::pak("cynkra/dir")
dir::add()
will:
- Add the ‘dir’ package to your “Suggests” dependencies in the “DESCRIPTION” file.
- Add your added folders to “.Rbuidignore”
- Load the code from your added folders into the
sysdata.rda
file in the R folder. - Load the objects into the session
- Document everything, like
devtools::document()
Sure, there you go!
devtools::document()
won’t work as intended, it will mess with your doc and NAMESPACE file, but you don’t need it, use onlyload_all()
. If you call it by mistakeload_all()
will repair the mess.devtools::check()
runsdocument()
at the end of the checks, that messes with the doc and the NAMESPACE file as well. The check itself is not affected though, here as wellload_all()
will clean up the mess.
This had been raised on r-devel multiple times but little interest has been shown to implement the feature, so here we are.