R Packages

Book description

Turn your R code into packages that others can easily download and use. This practical book shows you how to bundle reusable R functions, sample data, and documentation together by applying author Hadley Wickham’s package development philosophy. In the process, you’ll work with devtools, roxygen, and testthat, a set of R packages that automate common development tasks. Devtools encapsulates best practices that Hadley has learned from years of working with this programming language.

Ideal for developers, data scientists, and programmers with various backgrounds, this book starts you with the basics and shows you how to improve your package writing over time. You’ll learn to focus on what you want your package to do, rather than think about package structure.

  • Learn about the most useful components of an R package, including vignettes and unit tests
  • Automate anything you can, taking advantage of the years of development experience embodied in devtools
  • Get tips on good style, such as organizing functions into files
  • Streamline your development process with devtools
  • Learn the best way to submit your package to the Comprehensive R Archive Network (CRAN)
  • Learn from a well-respected member of the R community who created 30 R packages, including ggplot2, dplyr, and tidyr

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. In This Book
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Books Online
    5. How to Contact Us
    6. Acknowledgments
  2. I. Getting Started
  3. 1. Introduction
    1. Philosophy
    2. Getting Started
    3. Conventions
    4. Colophon
  4. 2. Package Structure
    1. Naming Your Package
      1. Requirements for a Name
      2. Strategies for Creating a Name
    2. Creating a Package
    3. RStudio Projects
      1. What Is an RStudio Project File?
    4. What Is a Package?
      1. Source Packages
      2. Bundled Packages
      3. Binary Packages
      4. Installed Packages
      5. In-Memory Packages
    5. What Is a Library?
  5. II. Package Components
  6. 3. R Code
    1. R Code Workflow
    2. Organizing Your Functions
    3. Code Style
      1. Object Names
      2. Spacing
      3. Curly Braces
      4. Line Length
      5. Indentation
      6. Assignment
      7. Commenting Guidelines
    4. Top-Level Code
      1. Loading Code
      2. The R Landscape
      3. When You Do Need Side Effects
      4. S4 Classes, Generics, and Methods
    5. CRAN Notes
  7. 4. Package Metadata
    1. Dependencies: What Does Your Package Need?
      1. Versioning
      2. Other Dependencies
    2. Title and Description: What Does Your Package Do?
    3. Author: Who Are You?
      1. On CRAN
    4. License: Who Can Use Your Package?
      1. On CRAN
    5. Version
    6. Other Components
  8. 5. Object Documentation
    1. The Documentation Workflow
    2. Alternative Documentation Workflow
    3. Roxygen Comments
    4. Documenting Functions
    5. Documenting Datasets
    6. Documenting Packages
    7. Documenting Classes, Generics, and Methods
      1. S3
      2. S4
      3. RC
    8. Special Characters
    9. Do Repeat Yourself
      1. Inheriting Parameters from Other Functions
      2. Documenting Multiple Functions in the Same File
    10. Text Formatting Reference Sheet
      1. Character Formatting
      2. Links
      3. Lists
      4. Mathematics
      5. Tables
  9. 6. Vignettes: Long-Form Documentation
    1. Vignette Workflow
    2. Metadata
    3. Markdown
      1. Sections
      2. Lists
      3. Inline Formatting
      4. Tables
      5. Code
    4. Knitr
      1. Options
    5. Development Cycle
    6. Advice for Writing Vignettes
      1. Organization
    7. CRAN Notes
    8. Where to Go Next
  10. 7. Testing
    1. Test Workflow
    2. Test Structure
      1. Expectations
    3. Writing Tests
      1. What to Test
      2. Skipping a Test
      3. Building Your Own Testing Tools
    4. Test Files
    5. CRAN Notes
  11. 8. Namespace
    1. Motivation
    2. Search Path
    3. The NAMESPACE
    4. Workflow
    5. Exports
      1. S3
      2. S4
      3. RC
      4. Data
    6. Imports
      1. R Functions
      2. S3
      3. S4
      4. Compiled Functions
  12. 9. External Data
    1. Exported Data
      1. Documenting Datasets
    2. Internal Data
    3. Raw Data
    4. Other Data
    5. CRAN Notes
  13. 10. Compiled Code
    1. C++
      1. Workflow
      2. Documentation
      3. Exporting C++ Code
      4. Importing C++ Code
      5. Best Practices
    2. C
      1. Getting Started with .Call()
      2. Getting Started with .C()
      3. Workflow
      4. Exporting C Code
      5. Importing C Code
      6. Best Practices
    3. Debugging Compiled Code
    4. Makefiles
    5. Other Languages
    6. Licensing
    7. Development Workflow
    8. CRAN Issues
  14. 11. Installed Files
    1. Package Citation
    2. Other Languages
  15. 12. Other Components
    1. Demos
  16. III. Best Practices
  17. 13. Git and GitHub
    1. RStudio, Git, and GitHub
    2. Initial Setup
    3. Creating a Local Git Repository
    4. Seeing What’s Changed
    5. Recording Changes
    6. Best Practices for Commits
    7. Ignoring Files
    8. Undoing Mistakes
    9. Synchronizing with GitHub
    10. Benefits of Using GitHub
    11. Working with Others
    12. Issues
    13. Branches
    14. Making a Pull Request
    15. Submitting a Pull Request to Another Repo
    16. Reviewing and Accepting Pull Requests
    17. Learning More
  18. 14. Automated Checking
    1. Workflow
    2. Checks
      1. Check Metadata
      2. Package Structure
      3. Description
      4. Namespace
      5. R Code
      6. Data
      7. Documentation
      8. Demos
      9. Compiled Code
      10. Tests
      11. Vignettes
    3. Checking After Every Commit with Travis
      1. Basic Config
      2. Other Uses
  19. 15. Releasing a Package
    1. Version Number
    2. Backward Compatibility
    3. The Submission Process
      1. Test Environments
      2. Check Results
      3. Reverse Dependencies
    4. CRAN Policies
    5. Important Files
      1. README.md
      2. README.Rmd
      3. NEWS.md
    6. Release
      1. On Failure
      2. Binary Builds
    7. Prepare for Next Version
    8. Publicizing Your Package
    9. Congratulations!
  20. Index

Product information

  • Title: R Packages
  • Author(s): Hadley Wickham
  • Release date: March 2015
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491910542