Tools to Make Developing R Packages Easier
Collection of package development tools.
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.
# Install devtools from CRAN install.packages("devtools") # Or the development version from GitHub: # install.packages("devtools") devtools::install_github("r-lib/devtools")
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 recommended practice.
Frequent development tasks:
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 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
test()reloads your code with
load_all(), then runs all
test_coverage()runs test coverage on your package with covr. This makes it easy to see what parts of your package could use more tests!
Building and installing:
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
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:
install_url()from an arbitrary url
install_svn()from an arbitrary git or SVN repository
install_local()from a local file on disk
install_version()from a specific version on CRAN
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 and release:
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 gives a comprehensive treatment of all common parts of package development and uses devtools throughout. The Package structure chapter is a great place to get started understanding the parts of a package and how they work together.
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. Currently devtools is undergoing a conscious uncoupling to split out functionality into smaller, more tightly focussed packages. This includes:
testthat: Writing and running tests (i.e.
roxygen2: Function and package documentation (i.e.
remotes: Installing packages (i.e.
pkgbuild: Building binary packages (including checking if build tools are available) (i.e.
pkgload: Simulating package loading (i.e.
rcmdcheck: Running R CMD check and reporting the results (i.e.
revdepcheck: Running R CMD check on all reverse dependencies, and figuring out what's changed since the last CRAN release (i.e.
sessioninfo: R session info (i.e.
usethis: Automating package setup (i.e.
Generally, you should not need to worry about these different packages, because devtools installs them all 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.
Code of conduct
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.
Functions in devtools
|dev_packages||Return a vector of names of packages loaded by devtools|
|dr_github||Diagnose potential GitHub issues|
|build_manual||Create package pdf manual|
|github_pat||Retrieve GitHub personal access token.|
|run_examples||Run all examples in a package.|
|save_all||Save all documents in an active IDE session.|
|has_tests||Was devtools installed with tests?|
|submit_cran||Submit a package to CRAN.|
|system_check||Run a system command and check if it succeeds.|
|check||Build and check a package, cleaning up automatically on success.|
|build_vignettes||Build package vignettes.|
|devtools||Package development tools for R.|
|as.package||Coerce input to a package.|
|load_all||Load complete package.|
|loaded_packages||Return a vector of names of attached packages|
|reload||Unload and reload package.|
|revdep||Reverse dependency tools.|
|bash||Open bash shell in package directory.|
|document||Use roxygen to document a package.|
|show_news||Show package news|
|dr_devtools||Diagnose potential devtools issues|
|is.package||Is the object a package?|
|source_gist||Run a script on gist|
|check_failures||Parses R CMD check log file for ERRORs, WARNINGs and NOTEs|
|lint||Lint all source files in a package.|
|missing_s3||Find missing s3 exports.|
|wd||Set working directory.|
|package_file||Find file in a package.|
|build_readme||Build a Rmarkdown README for a package|
|uninstall||Uninstall a local development package.|
|build_site||Execute pkgdown build_site in a package|
|check_rhub||Run CRAN checks for package on r-hub|
|check_man||Check documentation, as R CMD check does.|
|clean_vignettes||Clean built vignettes.|
|check_win||Build windows binary package.|
|dev_mode||Activate and deactivate development mode.|
|install||Install a local development package.|
|install_deps||Install package dependencies if needed. install_deps() will install the user dependencies needed to run the package, install_dev_deps() will also install the development dependencies needed to test and build the package.|
|release||Release package to CRAN.|
|release_checks||Custom devtools release checks.|
|r_env_vars||Environment variables to set when calling R|
|source_url||Run a script through some protocols such as http, https, ftp, etc.|
|reexports||Objects exported from other packages|
|test||Execute test_that tests in a package.|
|system_output||Run a system command and capture the output.|
|devtest||Return the path to one of the packages in the devtools test dir|
Vignettes of devtools
Last month downloads
|License||GPL (>= 2)|
|Packaged||2018-10-26 20:28:58 UTC; jhester|
|Date/Publication||2018-10-26 21:10:41 UTC|
|suggests||BiocInstaller , BiocManager , bitops , covr (>= 3.2.0) , crayon , curl (>= 0.9) , evaluate , foghorn (>= 1.0.1) , gmailr (> 0.7.0) , knitr , lintr (>= 0.2.1) , MASS , mockery , pingr , pkgdown , Rcpp (>= 0.10.0) , rhub , rmarkdown , roxygen2 (>= 6.1.0) , rversions , spelling (>= 1.1) , testthat (>= 1.0.2) , whisker|
|imports||callr , cli , digest , git2r (>= 0.23.0) , httr (>= 0.4) , jsonlite , memoise (>= 1.0.0) , pkgbuild (>= 1.0.2) , pkgload (>= 1.0.1) , rcmdcheck (>= 1.3.0) , remotes (>= 2.0.0) , rstudioapi (>= 0.6.0.9000) , sessioninfo , stats , tools , usethis (>= 1.4.0) , utils , withr|
|depends||R (>= 3.0.2)|
|Contributors||RStudio, Hadley Wickham, Winston Chang, R Core team|
Include our badge in your README