Movatterモバイル変換


[0]ホーム

URL:


Skip to content

devtools

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.

Installation

# Install devtools from CRANinstall.packages("devtools")# Or the development version from GitHub:# install.packages("pak")pak::pak("r-lib/devtools")

Cheatsheet

thumbnail of package development cheatsheet

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() simulates installing and reloading your package, loading R code inR/, compiled shared objects insrc/ and data files indata/. During development you would usually want to access all functions (even un-exported internal ones) soload_all() works as if all functions were exported in the packageNAMESPACE.

  • document() updates generated documentation inman/, file collation andNAMESPACE.

  • test() reloads your code withload_all(), then runs alltestthat tests.

  • test_coverage() runs test coverage on your package withcovr. This makes it easy to see what parts of your package could use more tests!

Building and installing:

Check and release:

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

  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 athttps://r-pkgs.org and in paperback format.
    • TheWhole Game andPackage structure chapters make great places to start.
  2. Posit Community - package development is a great place to ask specific questions related to package development.

  3. 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.

  4. There are a number of fantastic blog posts on writing your first package, including

  5. Writing R Extensions 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 aconscious uncoupling to split out functionality into smaller, more tightly focussed packages. This includes:

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. usesessioninfo::session_info() rather thandevtools::session_info(), orremotes::install_github() vsdevtools::install_github().

However for day to day development we recommend you continue to uselibrary(devtools) to quickly load all needed development tools, just likelibrary(tidyverse) quickly loads all the tools necessary for data exploration and visualization.

Code of conduct

Please note that the devtools project is released with aContributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Links

License

Community

Citation

Developers


[8]ページ先頭

©2009-2025 Movatter.jp