Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Hadley Wickham, Jenny Bryan

Rating No ratings yet

Turn your R code into packages that others can easily install and use. With this fully updated edition, developers and data scientists will learn how to bundle reusable R functions, sample data, and documentation together by applying the package development philosophy used by the team that maintains the "tidyverse" suite of packages. In the process, you'll learn how to automate common development tasks using a set of R packages, including devtools, usethis, testthat, and roxygen2. Authors Hadley Wickham and Jennifer Bryan from Posit (formerly known as RStudio) help you create packages quickly, then teach you how to get better over time. You'll be able to focus on what you want your package to do as you progressively develop greater mastery of the structure of a package. With this book, you will: • Learn the key components of an R package, including code, documentation, and tests • Streamline your development process with devtools and the RStudio IDE • Get tips on effective habits such as organizing functions into files • Get caught up on important new features in the devtools ecosystem • Learn about the art and science of unit testing, using features in the third edition of testthat • Turn your existing documentation into a beautiful and user friendly website with pkgdown • Gain an appreciation of the benefits of modern code hosting platforms, such as GitHub

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A practical, opinionated guide to turning loose R scripts into installable, tested, documented packages, written by the maintainers of the tidyverse toolchain. Best for R users who already write functions and want to share them reliably with others (or their future selves). 【Book Arc】 - **Opening (~0%–10%)**: Frames the whole game — what an R package actually is (code, docs, tests, data) and why packaging beats copy-pasting scripts. Introduces the core toolchain: devtools, usethis, testthat, roxygen2. - **Early (~10%–35%)**: Walks through creating a first package end-to-end (the `regexcite` example), covering `create_package()`, DESCRIPTION metadata, licensing, `check()`, `test()`, and `load_all()`. Solves the "where do I even start" problem. - **Middle (~35%–60%)**: Deepens structure and workflow — package states (source/bundled/binary), `.Rbuildignore`, dependencies and `use_package()`, exporting functions, and the discipline of running `R CMD check` iteratively. Also covers the "package within" refactor: extracting helpers from a messy script. - **Late (~60%–85%)**: The craft chapters — code style, respecting the R landscape, managing state with `withr`/`on.exit()`, package data, and the art and science of testing with testthat (basics, test design, advanced techniques). - **Ending (~85%–100%)**: Documentation with roxygen2, building a pkgdown website, and the release path — reverse dependency checks, CRAN submission, and handling failure modes. 【Key Takeaways】 - **Packages are the unit of reusable R code** (Opening): bundling functions, data, docs, and tests together is what makes code installable and dependable, not just shareable. - **Start with the whole game, then refine** (Early): the book's `regexcite` walkthrough gets a working package skeleton fast, then layers on correctness — a deliberate "make it work, then make it right" progression. - **`check()` is your constant health monitor** (Middle): run it often; ERRORs must be fixed, WARNINGs matter for CRAN, and NOTEs are worth eliminating when cheap. Long gaps between checks make bugs harder to isolate. - **Dependencies need explicit declaration** (Middle): even base-adjacent functions like `stats::median()` must be declared for CRAN — `use_package()` and the DESCRIPTION file are the mechanism. - **Testing is a discipline, not an afterthought** (Late): testthat's `test_that()`/`expect_equal()` patterns, plus `covr` for coverage, turn tests into a safety net that runs on every check. - **Respect the R landscape** (Late): code should avoid surprising side effects; use `withr` and `on.exit()` to manage and restore state cleanly. - **Documentation is part of the product** (Ending): roxygen2 comments generate function docs, and pkgdown turns them into a user-friendly website — documentation is written alongside code, not after. - **Releasing is a process with known failure modes** (Ending): reverse dependency checks, breaking-change awareness, and CRAN submission comments are all part of shipping responsibly. 【Reading Tips】 - **Deep-read the Early walkthrough** (~10%–35%): following `regexcite` step by step is the fastest way to internalize the workflow; skim it later as reference. - **Skim the contributor acknowledgments** (Early, ~16%–19%) — no conceptual content, safe to skip entirely. - **Treat the testing chapters (Late) as the hardest material**: design and advanced testing reward slow reading and hands-on practice with your own package. - **Keep `check()` running as you read**: the book's advice only sticks if you apply it to a real package you're building. - **Use the Ending as a checklist** when you're actually ready to release, not as front-to-back reading. 【Coverage Limits】 This guide is synthesized from stratified excerpts and a table of contents; specific code examples, chapter numbering, and detailed API behavior are only partially visible, so some finer points may be understated.
Page 5
62 5. The Package Within. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Alfa: A Script T...
View in text
Excerpt 2
@mjkanji (Muhammad Jarir Kanji), @mkuehn10 (Michael Kuehn), @mllg (Michel Lang), @mohamed-180 (Mohamed El-Desokey), @moodymudskip‐ per (Antoine Fabri), @Mooh...
View in text
Excerpt 3
rendered README.md simply by visiting regexcite on GitHub. Finally, don’t forget to do one last commit. And push, if you’re using GitHub. The End: check() an...
View in text
Excerpt 4
mpact on your package, it is reasonable to just tolerate it. Make sure that doesn’t lead to you ignoring other issues that really should be addressed. check(...
View in text
Excerpt 5
) or cleared without execution with withr::deferred_clear(). Without this feature, it can be tricky to experiment with code that needs cleanup “on exit,” bec...
View in text
Excerpt 6
he standard build matrix we use for continuous integration. • Packages with a lower level of use may not need this level of rigor. The main takeaway is: if y...
View in text
Excerpt 7
DESCRIPTION. Listing a package in either Depends or Imports ensures that it’s installed when needed. The main difference is that a package you list in Import...
View in text
Excerpt 8
instead link to a copy installed elsewhere on the system). • You’ve copied a small amount of R code from another package to avoid taking a dependency. Genera...
View in text
Tags
AI categories
Programming LanguageSoftwareData
ISBN: 109813494X
Publisher: O'Reilly Media
Publish Year: 2023
Language: English
Pages: 382
File Format: PDF
File Size: 4.4 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…