# devtools The aim of devtools is to make package development easier by providing R functions that simplify and expedite common tasks. [R Packages](https://r-pkgs.org/) is a book based around this workflow. ## Installation ``` r # Install devtools from CRAN install.packages("devtools") # Or the development version from GitHub: # install.packages("pak") pak::pak("r-lib/devtools") ``` ## Cheatsheet [![thumbnail of package development cheatsheet](https://github.com/rstudio/cheatsheets/raw/main/pngs/thumbnails/package-development-thumbs.png)](https://raw.githubusercontent.com/rstudio/cheatsheets/main/package-development.pdf) ## Usage 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. ### Frequent development tasks: - [`load_all()`](https://devtools.r-lib.org/reference/load_all.md) 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()`](https://devtools.r-lib.org/reference/load_all.md) works as if all functions were exported in the package `NAMESPACE`. - [`document()`](https://devtools.r-lib.org/reference/document.md) updates generated documentation in `man/`, file collation and `NAMESPACE`. - [`test()`](https://devtools.r-lib.org/reference/test.md) reloads your code with [`load_all()`](https://devtools.r-lib.org/reference/load_all.md), then runs all `testthat` tests. - [`test_coverage()`](https://devtools.r-lib.org/reference/test.md) runs test coverage on your package with [covr](https://github.com/r-lib/covr). This makes it easy to see what parts of your package could use more tests! ### Building and installing: - [`install()`](https://devtools.r-lib.org/reference/install.md) reinstalls the package, detaches the currently loaded version then reloads the new version with [`library()`](https://rdrr.io/r/base/library.html). Reloading a package is not guaranteed to work: see the documentation for [`unload()`](https://pkgload.r-lib.org/reference/unload.html) for caveats. - [`build()`](https://devtools.r-lib.org/reference/build.md) 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_github()`](https://devtools.r-lib.org/reference/install-deprecated.md) from GitHub - [`install_gitlab()`](https://devtools.r-lib.org/reference/install-deprecated.md) from GitLab - [`install_bitbucket()`](https://devtools.r-lib.org/reference/install-deprecated.md) from Bitbucket - [`install_url()`](https://devtools.r-lib.org/reference/install-deprecated.md) from an arbitrary url - [`install_git()`](https://devtools.r-lib.org/reference/install-deprecated.md) and [`install_svn()`](https://devtools.r-lib.org/reference/install-deprecated.md) from an arbitrary git or SVN repository - [`install_local()`](https://devtools.r-lib.org/reference/install-deprecated.md) from a local file on disk - [`install_version()`](https://devtools.r-lib.org/reference/install-deprecated.md) from a specific version on CRAN - [`update_packages()`](https://devtools.r-lib.org/reference/install-deprecated.md) updates a package to the latest version. This works both on packages installed from CRAN as well as those installed from any of the `install_*` functions. ### Check and release: - [`check()`](https://devtools.r-lib.org/reference/check.md) updates the documentation, then builds and checks the package locally. - [`check_win_release()`](https://devtools.r-lib.org/reference/check_win.md), [`check_win_devel()`](https://devtools.r-lib.org/reference/check_win.md), and [`check_mac_release()`](https://devtools.r-lib.org/reference/check_mac_release.md) check a package using [win-builder](https://win-builder.r-project.org/) or . - [`release()`](https://devtools.r-lib.org/reference/release.md) and [`submit_cran()`](https://devtools.r-lib.org/reference/submit_cran.md) handle the mechanics of CRAN submission with or without, respectively, (re)-running lots of local checks. ## Learning more R package development can be intimidating, however there are now a number of valuable resources to help! [![Cover image of R Packages book](http://r-pkgs.org/images/cover-2e-small.png)](https://r-pkgs.org) 1. R Packages is a book that gives a comprehensive treatment of all common parts of package development and uses devtools throughout. - The first edition is no longer available online, but it is still in print. Note that it has grown somewhat out of sync with the current version of devtools. - A second edition that reflects the current state of devtools, plus new topics such as package websites and GitHub Actions, is available at and in paperback format. - The [Whole Game](https://r-pkgs.org/whole-game.html) and [Package structure](https://r-pkgs.org/package-structure-state.html) chapters make great places to start. 2. [Posit Community - package development](https://forum.posit.co/c/package-development/11) is a great place to ask specific questions related to package development. 3. [rOpenSci packages](https://devguide.ropensci.org/) has extensive documentation on best practices for R packages looking to be contributed to rOpenSci, but also very useful general recommendations for package authors. 4. There are a number of fantastic blog posts on writing your first package, including - [Writing an R package from scratch - Hilary Parker](https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/) - [How to develop good R packages - Maëlle Salmon](https://masalmon.eu/2017/12/11/goodrpackages/) - [Making your first R package - Fong Chun Chan](https://tinyheero.github.io/jekyll/update/2015/07/26/making-your-first-R-package.html) - [Writing an R package from scratch - Tomas Westlake](https://r-mageddon.netlify.app/post/writing-an-r-package-from-scratch/) 5. [Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html) is the exhaustive, canonical reference for writing R packages, maintained by the R core developers. ## Conscious uncoupling 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](https://web.archive.org/web/20140326060230/https://www.goop.com/journal/be/conscious-uncoupling) to split out functionality into smaller, more tightly focussed packages. This includes: - [testthat](https://github.com/r-lib/testthat): Writing and running tests (i.e. [`test()`](https://devtools.r-lib.org/reference/test.md)). - [roxygen2](https://github.com/r-lib/roxygen2): Function and package documentation (i.e. [`document()`](https://devtools.r-lib.org/reference/document.md)). - [pak](https://pak.r-lib.org): Installing packages (i.e. [`pak::pak()`](https://pak.r-lib.org/reference/pak.html)). - [pkgbuild](https://github.com/r-lib/pkgbuild): Building binary packages (including checking if build tools are available) (i.e. [`build()`](https://devtools.r-lib.org/reference/build.md)). - [pkgload](https://github.com/r-lib/pkgload): Simulating package loading (i.e. [`load_all()`](https://devtools.r-lib.org/reference/load_all.md)). - [rcmdcheck](https://github.com/r-lib/rcmdcheck): Running R CMD check and reporting the results (i.e. [`check()`](https://devtools.r-lib.org/reference/check.md)). - [revdepcheck](https://github.com/r-lib/revdepcheck): Running R CMD check on all reverse dependencies, and figuring out what’s changed since the last CRAN release (i.e. `revdep_check()`). - [sessioninfo](https://github.com/r-lib/sessioninfo): R session info (i.e. [`session_info()`](https://sessioninfo.r-lib.org/reference/session_info.html)). - [usethis](https://github.com/r-lib/usethis): Automating package setup (i.e. `use_test()`). 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()`](https://sessioninfo.r-lib.org/reference/session_info.html) rather than [`devtools::session_info()`](https://sessioninfo.r-lib.org/reference/session_info.html), or `pak::pak("user/repo")` vs `devtools::install_github("user/repo")`. However for day to day development we recommend you continue to use [`library(devtools)`](https://devtools.r-lib.org/) to quickly load all needed development tools, just like [`library(tidyverse)`](https://tidyverse.tidyverse.org) quickly loads all the tools necessary for data exploration and visualization. ## Code of conduct Please note that the devtools project is released with a [Contributor Code of Conduct](https://github.com/r-lib/devtools/blob/main/.github/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms. # Package index ## Package development Primary commands used when developing a package. - [`build()`](https://devtools.r-lib.org/reference/build.md) : Build package - [`build_manual()`](https://devtools.r-lib.org/reference/build_manual.md) : Create package pdf manual - [`build_readme()`](https://devtools.r-lib.org/reference/build_readme.md) : Build README - [`build_site()`](https://devtools.r-lib.org/reference/build_site.md) : Run [`pkgdown::build_site()`](https://pkgdown.r-lib.org/reference/build_site.html) - [`check()`](https://devtools.r-lib.org/reference/check.md) [`check_built()`](https://devtools.r-lib.org/reference/check.md) : Build and check a package - [`check_doc_fields()`](https://devtools.r-lib.org/reference/check_doc_fields.md) : Check for missing documentation fields - [`check_mac_release()`](https://devtools.r-lib.org/reference/check_mac_release.md) [`check_mac_devel()`](https://devtools.r-lib.org/reference/check_mac_release.md) : Check a package on macOS - [`check_man()`](https://devtools.r-lib.org/reference/check_man.md) : Check documentation, as `R CMD check` does - [`check_win_devel()`](https://devtools.r-lib.org/reference/check_win.md) [`check_win_release()`](https://devtools.r-lib.org/reference/check_win.md) [`check_win_oldrelease()`](https://devtools.r-lib.org/reference/check_win.md) : Check a package on Windows - [`document()`](https://devtools.r-lib.org/reference/document.md) : Use roxygen to document a package - [`load_all()`](https://devtools.r-lib.org/reference/load_all.md) : Load complete package - [`spell_check()`](https://devtools.r-lib.org/reference/spell_check.md) : Spell checking - [`test()`](https://devtools.r-lib.org/reference/test.md) [`test_active_file()`](https://devtools.r-lib.org/reference/test.md) [`test_coverage()`](https://devtools.r-lib.org/reference/test.md) [`test_coverage_active_file()`](https://devtools.r-lib.org/reference/test.md) : Execute testthat tests in a package ## Package installation - [`install()`](https://devtools.r-lib.org/reference/install.md) : Install a local development package - [`uninstall()`](https://devtools.r-lib.org/reference/uninstall.md) : Uninstall a local development package ## Utilities - [`dev_sitrep()`](https://devtools.r-lib.org/reference/dev_sitrep.md) : Report package development situation - [`lint()`](https://devtools.r-lib.org/reference/lint.md) : Lint all source files in a package - [`run_examples()`](https://devtools.r-lib.org/reference/run_examples.md) : Run all examples in a package - [`reexports`](https://devtools.r-lib.org/reference/reexports.md) [`parse_deps`](https://devtools.r-lib.org/reference/reexports.md) [`check_dep_version`](https://devtools.r-lib.org/reference/reexports.md) [`with_debug`](https://devtools.r-lib.org/reference/reexports.md) [`clean_dll`](https://devtools.r-lib.org/reference/reexports.md) [`has_devel`](https://devtools.r-lib.org/reference/reexports.md) [`find_rtools`](https://devtools.r-lib.org/reference/reexports.md) [`is_loading`](https://devtools.r-lib.org/reference/reexports.md) [`unload`](https://devtools.r-lib.org/reference/reexports.md) [`session_info`](https://devtools.r-lib.org/reference/reexports.md) [`package_info`](https://devtools.r-lib.org/reference/reexports.md) : Objects exported from other packages - [`source_gist()`](https://devtools.r-lib.org/reference/source_gist.md) : Run a script on gist - [`source_url()`](https://devtools.r-lib.org/reference/source_url.md) : Run a script through some protocols such as http, https, ftp, etc - [`save_all()`](https://devtools.r-lib.org/reference/save_all.md) : Save all documents in an active IDE session ## Deprecated - [`bash()`](https://devtools.r-lib.org/reference/bash.md) **\[deprecated\]** : Open bash shell in package directory - [`build_rmd()`](https://devtools.r-lib.org/reference/build_rmd.md) **\[deprecated\]** : Build Rmarkdown files - [`build_vignettes()`](https://devtools.r-lib.org/reference/build_vignettes.md) **\[deprecated\]** : Build package vignettes - [`clean_vignettes()`](https://devtools.r-lib.org/reference/clean_vignettes.md) **\[deprecated\]** : Clean built vignettes - [`create()`](https://devtools.r-lib.org/reference/create.md) **\[deprecated\]** : Create a package - [`dev_mode()`](https://devtools.r-lib.org/reference/dev_mode.md) **\[deprecated\]** : Activate and deactivate development mode - [`install_bioc()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`install_bitbucket()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`install_cran()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`install_dev()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`install_git()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`install_github()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`install_gitlab()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`install_local()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`install_svn()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`install_url()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`install_version()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`update_packages()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`dev_package_deps()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`github_pull()`](https://devtools.r-lib.org/reference/install-deprecated.md) [`github_release()`](https://devtools.r-lib.org/reference/install-deprecated.md) **\[deprecated\]** : Deprecated package installation functions - [`install_deps()`](https://devtools.r-lib.org/reference/install_deps.md) [`install_dev_deps()`](https://devtools.r-lib.org/reference/install_deps.md) **\[deprecated\]** : Install package dependencies if needed - [`missing_s3()`](https://devtools.r-lib.org/reference/missing_s3.md) **\[deprecated\]** : Find missing s3 exports - [`reload()`](https://devtools.r-lib.org/reference/reload.md) **\[deprecated\]** : Unload and reload package - [`release()`](https://devtools.r-lib.org/reference/release.md) **\[deprecated\]** : Release package to CRAN - [`show_news()`](https://devtools.r-lib.org/reference/show_news.md) **\[deprecated\]** : Show package news - [`wd()`](https://devtools.r-lib.org/reference/wd.md) **\[deprecated\]** : Set working directory - [`test_file()`](https://devtools.r-lib.org/reference/devtools-defunct.md) [`test_coverage_file()`](https://devtools.r-lib.org/reference/devtools-defunct.md) : Defunct functions # Articles ### All vignettes - [Depending on a development version](https://devtools.r-lib.org/articles/dependencies.md):