The aim of devtools is to make package development easier by providing R functions that simplify and expedite common tasks. R Packages is a book based around this workflow.
All devtools functions accept a path as an argument, e.g.
load_all("path/to/mypkg"). If you don’t specify a path, devtools will look in the current working directory - this is a recommended practice.
load_all() simulates installing and reloading your package, loading R code in
R/, compiled shared objects in
src/ and data files in
data/. During development you would usually want to access all functions (even un-exported internal ones) so
load_all() works as if all functions were exported in the package
document() updates generated documentation in
man/, file collation and
install() reinstalls the package, detaches the currently loaded version then reloads the new version with
library(). Reloading a package is not guaranteed to work: see the documentation for
unload() for caveats.
build() builds a package file from package sources. You can use it to build a binary version of your package.
install_* functions install an R package:
update_packages() updates a package to the latest version. This works both on packages installed from CRAN as well as those installed from any of the
check() updates the documentation, then builds and checks the package locally.
check_win() checks a package using win-builder, and
check_rhub() checks a package using r-hub. This allows you to easily check your package on all systems CRAN uses before submission.
release() makes sure everything is ok with your package (including asking you a number of questions), then builds and uploads to CRAN.
R package development can be intimidating, however there are now a number of valuable resources to help!
R Packages is a book that gives a comprehensive treatment of all common parts of package development and uses devtools throughout.
RStudio community - package development is a great place to ask specific questions related to package development.
rOpenSci packages has extensive documentation on best practices for R packages looking to be contributed to rOpenSci, but also very useful general recommendations for package authors.
There are a number of fantastic blog posts on writing your first package, including
Writing R Extensions is the exhaustive, canonical reference for writing R packages, maintained by the R core developers.
devtools started off as a lean-and-mean package to facilitate local package development, but over the years it accumulated more and more functionality. devtools has undergone a conscious uncoupling to split out functionality into smaller, more tightly focussed packages. This includes:
revdepcheck: Running R CMD check on all reverse dependencies, and figuring out what’s changed since the last CRAN release (i.e.
usethis: Automating package setup (i.e.
Generally, you would not need to worry about these different packages, because devtools installs all of them automatically. You will need to care, however, if you’re filing a bug because reporting it at the correct place will lead to a speedier resolution.
You may also need to care if you are trying to use some devtools functionality in your own package or deployed application. Generally in these cases it is better to depend on the particular package directly rather than depend on devtools, e.g. use
sessioninfo::session_info() rather than
However for day to day development we recommend you continue to use
library(devtools) to quickly load all needed development tools, just like
library(tidyverse) quickly loads all the tools necessary for data exploration and visualization.
Please note that the devtools project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.