pkgbuild
The goal of pkgbuild is to make it easy to build packages with compiled code. It provides tools to configure your R session, and check that everything is working ok. If you are using RStudio, it also helps you trigger automatic install of the build tools.
Installation
Install the released version from CRAN
install.packages("pkgbuild")
Or install the development version from GitHub:
# install.packages("pak")
pak::pak("r-lib/pkgbuild")
Example
# Check that you have the build tools installed
pkgbuild::check_build_tools(debug = TRUE)
# Build a package
pkgbuild::build("/path/to/my/package")
# Run your own code in an environment guaranteed to
# have build tools available
pkgbuild::with_build_tools(my_code)
Configuration
DESCRIPTION
entries
Config/build/clean-inst-doc
can be set toFALSE
to avoid cleaning upinst/doc
when building a source package. Set it toTRUE
to force a cleanup. See theclean_doc
argument ofbuild()
as well.Config/build/copy-method
can be used to avoid copying large directories inR CMD build
. It works by copying (or linking) the files of the package to a temporary directory, leaving out the (possibly large) files that are not part of the package. Possible values:none
: pkgbuild does not copy the package tree. This is the default.copy
: the package files are copied to a temporary directory beforeR CMD build
.link
: the package files are symbolic linked to a temporary directory beforeR CMD build
. Windows does not have symbolic links, so on Windows this is equivalent tocopy
.
You can also use the
pkg.build_copy_method
option or thePKG_BUILD_COPY_METHOD
environment variable to set the copy method. The option is consulted first, then theDESCRIPTION
entry, then the environment variable.Config/build/extra-sources
can be used to define extra source files for pkgbuild to decide whether a package DLL needs to be recompiled inneeds_compile()
. The syntax is a comma separated list of file names, or globs. (See?utils::glob2rx()
.) E.g.src/rust/src/*.rs
orconfigure*
.
Options
pkg.build_copy_method
: use this option to avoid copying large directories when building a package. See possible values above, at theConfig/build/copy-method
DESCRIPTION
entry.pkg.build_extra_flags
: set this toFALSE
to to opt out from adding debug compiler flags incompile_dll()
. Takes precedence over thePKG_BUILD_EXTRA_FLAGS
environment variable. Possible values:TRUE
: add extra flags,FALSE
: do not add extra flags,"missing"
: add extra flags if the user does not have a$HOME/.R/Makevars
file.
pkg.build_stop_for_warnings
: if it is set toTRUE
, then pkgbuild will stop forR CMD build
errors. It takes precedence over thePKG_BUILD_STOP_FOR_WARNINGS
environment variable.
Environment variables
PKG_BUILD_COLOR_DIAGNOSTICS
: set it tofalse
to opt out of colored compiler diagnostics. Set it totrue
to force colored compiler diagnostics.PKG_BUILD_COPY_METHOD
: use this environment variable to avoid copying large directories when building a package. See possible values above, at theConfig/build/copy-method
DESCRIPTION
entry.PKG_BUILD_EXTRA_FLAGS
: set this tofalse
to to opt out from adding debug compiler flags incompile_dll()
. Thepkg.build_extra_flags
option takes precedence over this environment variable. Possible values:"true"
: add extra flags,"false"
: do not add extra flags,"missing"
: add extra flags if the user does not have a$HOME/.R/Makevars
file.
PKG_BUILD_STOP_FOR_WARNINGS
: if it is set totrue
, then pkgbuild will stop forR CMD build
errors. Thepkg.build_stop_for_warnings
option takes precedence over this environment variable.
Code of Conduct
Please note that the pkgbuild project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.