Introduction
devtools is an R package by Hadley Wickham and the r-lib team that removes the friction from R package development. Before devtools, building and testing packages required manual command-line invocations and configuration. devtools wraps these steps into simple R functions that work from an interactive R session or RStudio, making the edit-load-test cycle fast and natural.
What devtools Does
- Loads package source code into the current session with
load_all()for rapid iteration without reinstalling - Runs testthat test suites with
test()and reports results inline - Generates documentation from roxygen2 comments with
document() - Runs the full R CMD check suite with
check()to catch issues before CRAN submission - Installs packages from GitHub, GitLab, Bitbucket, and URLs with
install_github()and friends
Architecture Overview
devtools acts as a thin wrapper around a suite of focused packages: pkgload (for load_all()), pkgbuild (for building tarballs), rcmdcheck (for check()), remotes (for installing from remote sources), roxygen2 (for documentation), and testthat (for testing). This modular design means each component can be updated independently. devtools re-exports the key functions from these packages so developers only need to load one package.
Self-Hosting & Configuration
- Install from CRAN:
install.packages("devtools") - Create a new package skeleton with
usethis::create_package("mypackage") - Add tests with
usethis::use_testthat()and write test files intests/testthat/ - Configure CI with
usethis::use_github_action_check_standard()for automated R CMD check - Set
DESCRIPTIONfields (Imports, Suggests, License) and useusethis::use_package()to add dependencies
Key Features
load_all()simulates package installation by sourcing all R files and loading compiled code, enabling a fast development loopinstall_github("owner/repo")installs packages directly from GitHub without manual downloadcheck()catches common issues (missing docs, broken examples, test failures) before CRAN submission- Tight integration with usethis for scaffolding package infrastructure (tests, CI, badges, NEWS, vignettes)
- Works in both interactive R sessions and RStudio with dedicated build pane support
Comparison with Similar Tools
- usethis (R) — complementary package for one-time setup tasks (creating files, configuring CI); devtools covers the iterative development cycle
- pak (R) — faster package installer; devtools focuses on development workflow, not just installation
- remotes (R) — handles remote installation only; devtools provides the full develop-test-check-install workflow
- setuptools / pip (Python) — Python packaging tools; devtools is the R equivalent but more opinionated and integrated
- npm / cargo — language-specific package managers; devtools is unique in combining development workflow with package management
FAQ
Q: Do I need devtools to develop R packages? A: Not strictly, but it makes the process much simpler. Without it, you would use R CMD commands from the terminal.
Q: What is the difference between devtools and usethis? A: usethis handles one-time setup (create files, configure settings). devtools handles repeated actions (load, test, check, install). They work together.
Q: Can I install packages from private GitHub repos?
A: Yes. Set a GITHUB_PAT environment variable with a personal access token and use install_github("owner/private-repo").
Q: Does devtools work outside of RStudio? A: Yes. All devtools functions work in any R console, terminal, or IDE. RStudio provides additional UI integration but is not required.