Executes all steps to process an R package written in R Markdown format from source to installation in one go:
Purl all relevant
Rmd/*.Rmd
files toR/*.gen.R
files usingpurl_rmd()
.Re-generate the pkgdown reference index based on the package's main R Markdown file using
gen_pkgdown_ref()
(ifgen_pkgdown_ref = TRUE
).Re-build the package documentation using
devtools::document()
(ifdocument = TRUE
).Build and install the package (if
build_and_install = TRUE
). This is done either usingrstudioapi::executeCommand(commandId = "buildFull")
(ifuse_rstudio_api = TRUE
) or usingdevtools::install()
(ifuse_rstudio_api = FALSE
).Restarts the R session using
rstudioapi::restartSession()
(if eitherrestart_r_session = TRUE
oruse_rstudio_api = TRUE
).
Usage
process_pkg(
path = ".",
add_copyright_notice = pal::pkg_config_val("add_copyright_notice"),
add_license_notice = pal::pkg_config_val("add_license_notice"),
gen_pkgdown_ref = pal::pkg_config_val("gen_pkgdown_ref"),
env = parent.frame(),
document = TRUE,
build_and_install = TRUE,
restart_r_session = build_and_install,
use_rstudio_api = NULL,
quiet = TRUE,
roclets = NULL,
args = getOption("devtools.install.args"),
dependencies = NA,
upgrade = "never",
keep_source = getOption("keep.source.pkgs")
)
Arguments
- path
Path to the root of the package directory.
- add_copyright_notice
Whether or not to add a copyright notice at the beginning of the generated
.R
files as recommended by e.g. the GNU licenses. The notice consists of the name and description of the program and the wordCopyright (C)
followed by the release years and the name(s) of the copyright holder(s), or if not specified, the author(s). The year is always the current year. All the other information is extracted from the package'sDESCRIPTION
file. A logical scalar. Only applies ifpath
is actually an R package directory.- add_license_notice
Whether or not to add a license notice at the beginning of the generated
.R
files as recommended by e.g. the GNU licenses. The license is determined from the package'sDESCRIPTION
file and currently only theAGPL-3.0-or-later
license is supported. A logical scalar. Only applies ifpath
is actually an R package directory.- gen_pkgdown_ref
Whether or not to overwrite pkgdown's reference index in the configuration file
_pkgdown.yml
with an auto-generated one based on the main input file as described ingen_pkgdown_ref()
. A logical scalar. Only applies ifpath
is actually an R package directory, pkgdown is set up and a main R Markdown file exists.- env
Environment to evaluate R Markdown inline code expressions in when generating the pkgdown reference index. Only relevant if
gen_pkgdown_ref = TRUE
.- document
Whether or not to re-build the package documentation after purling
Rmd/*.Rmd
toR/*.gen.R
.- build_and_install
Whether or not to build and install the package after purling
Rmd/*.Rmd
toR/*.gen.R
.- restart_r_session
Whether or not to restart the R session. Highly recommended if
build_and_install = TRUE
, but only possible when R is run within RStudio. Note that the R session is always restarted ifuse_rstudio_api = TRUE
.- use_rstudio_api
Whether or not to rely on the RStudio API to install the built package (which always triggers an R session restart regardless of
restart_r_session
). IfNULL
, the RStudio API is automatically used if possible, i.e. RStudio is running. Note that installation without the RStudio API has known issues, see section Details below for further information.- quiet
Whether or not to suppress printing status output from internal processing.
- roclets
Character vector of roclet names to use with package. The default,
NULL
, uses the roxygenroclets
option, which defaults toc("collate", "namespace", "rd")
.- args
An optional character vector of additional command line arguments to be passed to
R CMD INSTALL
. This defaults to the value of the option"devtools.install.args"
.- dependencies
Which dependencies do you want to check? Can be a character vector (selecting from "Depends", "Imports", "LinkingTo", "Suggests", or "Enhances"), or a logical vector.
TRUE
is shorthand for "Depends", "Imports", "LinkingTo" and "Suggests".NA
is shorthand for "Depends", "Imports" and "LinkingTo" and is the default.FALSE
is shorthand for no dependencies (i.e. just check this package, not its dependencies).The value "soft" means the same as
TRUE
, "hard" means the same asNA
.You can also specify dependencies from one or more additional fields, common ones include:
Config/Needs/website - for dependencies used in building the pkgdown site.
Config/Needs/coverage for dependencies used in calculating test coverage.
- upgrade
Should package dependencies be upgraded? One of "default", "ask", "always", or "never". "default" respects the value of the
R_REMOTES_UPGRADE
environment variable if set, and falls back to "ask" if unset. "ask" prompts the user for which out of date packages to upgrade. For non-interactive sessions "ask" is equivalent to "always".TRUE
andFALSE
are also accepted and correspond to "always" and "never" respectively.- keep_source
If
TRUE
will keep the srcrefs from an installed package. This is useful for debugging (especially inside of RStudio). It defaults to the option"keep.source.pkgs"
.
Details
Note that the installation via devtools::install()
(i.e. use_rstudio_api = FALSE
) is known to fail in certain situations (lazy-load database corruption)
due to unresolved deficiencies in R's namespace unloading. If you encounter an error, simply restart the
R session and try again.
This function is also registered as an RStudio add-in, allowing RStudio users to assign a custom shortcut to it and to invoke it from the command palette.
See also
Other high-level functions:
lint_rmd()
,
load_pkg()
,
purl_rmd()
,
run_nopurl_rmd()