library(rpkgkit)
dir <- tempdir()
usethis::create_package(path = dir, open = FALSE)
usethis::use_pkgdown()use_zzz() creates a package documentation file with
.onLoad, .onAttach, and %||%. It
is similar to usethis::use_package_doc() while also
providing a useful starting template.
_pkgdown referencecheck_pkgdown_reference() identifies exported functions
that are absent from the reference section of
_pkgdown.yml.
use_clangd() writes a .clangd configuration
file that lets the clangd language server find the system R headers and
the include/ directory of the packages you pass in
include (Rcpp, RcppEigen and
RcppArmadillo by default). Packages that are not installed
are skipped with a warning.
When path is a package root, the file also disables
background indexing for the R/ directory (which holds no
C++ code) and adds .clangd to
.Rbuildignore.
use_jarl() writes a jarl.toml file for jarl, the linter written in
Rust. The file pins down the linting behaviour of every
jarl invocation, so the command line, your editor and CI
all agree. It enables the opt-in TESTTHAT group of rules,
skips vendored files, and lints the code inside @examples
and @examplesIf tags.
jarl reads a single configuration file: the closest
jarl.toml in the current directory or any of its parents,
and finally the one in your user configuration directory. When
path is a package root, jarl.toml is also
added to .Rbuildignore so it stays out of the built
tarball.
Read the configuration
reference for options such as select,
ignore and per-file-ignores, and the continuous integration
guide to run jarl check on every push with the
etiennebacher/setup-jarl action.
An addin is an exported function registered in
inst/rstudio/addins.dcf; RStudio then lists it in the
Addins menu and runs it in the current session.
use_tidy_addin() writes that entry for you:
The entry is appended above the existing ones, so the newest addin
comes first, and a Binding that is already registered is
never added twice:
Name: check_my_pkg
Description: Check my package
Binding: check_my_pkg
Interactive: false
Before writing, the function checks that path is a
package and that fn_name is exported in
NAMESPACE, reads the body of the function (from the
installed package, or from R/ when the package has not been
documented yet), and warns when that body calls no
rstudioapi function, or, for an
Interactive = TRUE addin, no
shiny/miniUI function. In an interactive
session the warning asks whether to continue; a non-interactive session
only reports it and writes the entry.
rpkgkit registers its own addins in
inst/rstudio/addins.dcf, so every detector can be run from
the menu without typing the call:
| Addin | What it checks |
|---|---|
detect_lost_glue_brace /
package_lost_glue_brace |
unmatched {} in glue()/cli
strings |
detect_print_and_cat /
package_print_and_cat |
CRAN-unsafe print()/cat() calls |
detect_fn_arg_path /
package_fn_arg_path |
path-like arguments of exported functions that default to a concrete location |
package_unmatched_nocov_marker |
unmatched # nocov start / # nocov end
markers |
check_pkgdown_reference |
exported functions missing from the _pkgdown.yml
reference |
The detect_* addins work on the active editor, the
package-wide ones on the current package directory. They only report;
none of them rewrites a file. In Positron, addins need a third-party
extension such as Positron R Wizard.
use_vendor() records attribution and licensing
information when incorporating selected source files from a permissively
licensed GitHub R package. It creates an inst/vendor/
directory, a R/vendor-*.R file, and updates relevant
DESCRIPTION fields.
Only packages with a supported permissive license can be vendored. Review the acknowledgement text printed by the function and add it to your README when appropriate.
usethis extensionsUse the following helpers from the package root:
R 4.1.0 introduced the pipe (|>) and anonymous
function \(). If these syntaxes need to be used in a
package, the R package must require at least R version 4.1.0.
Another function is use_r(), which sets the
R-Version field in DESCRIPTION
automatically.
CITATION.cff files are plain text files with human- and machine-readable citation information for software and datasets.
Code developers can include such files in their source code repositories to let others know how to correctly cite their software.
This cannot replace
usethis::use_citation(), it just complements
project.
Use add_global_rbuildignore() and
add_global_gitgnore() to add the corresponding global
ignore-file templates to a package.
Each use_workflow_*() function copies a workflow
template bundled in inst/actions/ into the
.github/ directory of the target package. All of them
create the directories they need, abort instead of overwriting unless
overwrite = TRUE, and return the written path
invisibly.
use_workflow_version_update() installs
version_update.yml together with the
version-bumper composite action. The version is bumped from
the commit message (major/breaking,
feat/minor,
patch/fix), or explicitly through
workflow_dispatch. A bump is skipped when the new version
would exceed the highest version documented in NEWS.md, and
the version field of src/rust/Cargo.toml is
kept in sync when the package ships Rust code.
R CMD check on packages with Rust codeuse_workflow_rust_compatible_check() installs a
R-CMD-check.yaml that can download, compile and link Rust
crates, which is what packages built on
extendr/rextendr need. It replaces
usethis::use_github_action("check-standard") for such
packages.
The difference lies in the toolchain. The usethis
workflow only sets up R and leaves the runner default in place; on
Windows that default is an MSVC toolchain, while R and Rtools are GNU
based, so the static library produced by cargo cannot be
linked and the resulting build noise makes R CMD check
report a WARNING. The template used here follows the official
extendr CI:
dtolnay/rust-toolchain installs the requested toolchain
and, on Windows, additionally the x86_64-pc-windows-gnu
target that Rtools can link.fail-fast: false, so one broken platform does not hide
the others.R_REMOTES_NO_ERRORS_FROM_WARNINGS keeps download noise
from remotes and pak from surfacing as a check
failure.main to a test branchuse_workflow_test_branch() adds a workflow that runs
after R-CMD-check.yaml succeeds on
main/master and force-pushes the checked
commit to test. The sync is skipped when test
holds commits that are not reachable from main, so unmerged
work is never overwritten. Push experimental changes to
test and each push to main resets it
again.
Some packages need system development libraries (graphics and font
libraries, for example) to compile. check_sysdeps() detects
the package manager in use (dpkg, rpm,
pacman, apk or brew), checks each
dependency with it, and reports every hit and miss together with a
ready-to-paste install command for the missing ones.
With deps = NULL (the default), a built-in list of
graphics, font and solver libraries (freetype,
libjpeg, libpng, libtiff,
libwebp, harfbuzz, fribidi,
fontconfig, glpk) is checked using the names
that the detected package manager expects (for example
libwebp-devel and glpk-devel on rpm,
libwebp-dev and libglpk-dev on dpkg). Pass
your own names in deps, and optionally set
manager to check against a manager other than the detected
one:
The result is returned invisibly as a named logical vector, so it can
be reused in scripts. Set verbose = FALSE to keep the run
silent:
get_positron_version() reports the version of the
Positron IDE that hosts the current R session. It is useful for
diagnostics, bug reports, or for enabling IDE-specific behaviour only on
recent builds.
The version is looked up in three steps, in this order:
POSITRON_VERSION environment variable set by
Positron for its R sessions (POSITRON_LONG_VERSION, which
also carries the build number, when long = TRUE);.ps.positron_version() helper that the IDE injects
into the session;positron --version command-line tool.If the session does not run inside Positron and no
positron executable is on PATH, the function
returns NA_character_ instead of throwing an error, so it
is safe to call in any session, including CI.