R Packages
by Hadley Wickham and Jenny Bryan
Copyright 2023 Hadley Wickham and Jenny Bryan. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com.
- Editors: Sara Hunter and Aaron Black
- Production Editor: Aleeya Rahman
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Kate Dullea
- June 2023: Second Edition
Revision History for the Second Edition
- 2023-04-17: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781098134945 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. R Packages, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
The views expressed in this work are those of the author(s) and do not represent the publishers views. While the publisher and the author(s) have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author(s) disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-098-13488-4
Preface
Welcome!
Welcome to R packages by Hadley Wickham and Jennifer Bryan. Packages are the fundamental units of reproducible R code. They include reusable R functions, the documentation that describes how to use them, and sample data. In this book youll learn how to turn your code into packages that others can easily download and use. Writing a package can seem overwhelming at first. So start with the basics and improve it over time. It doesnt matter if your first version isnt perfect as long as the next version is better.
This is the work-in-progress 2nd edition of the book.
Welcome to the 2nd edition of R Packages! If youre familiar with the 1st edition, this preface describes the major changes so that you can focus your reading on the new areas.
There are several main goals for this edition:
Update to reflect changes in the devtools package, specifically, its conscious uncoupling into a set of smaller, more focused packages.
Expand coverage of workflow and process, alongside the presentation of all the important moving parts that make up an R package.
Cover entirely new topics, such as package websites and GitHub Actions.
All content has been completely revised and updated. Many chapters are new or re-organized and a couple have been removed:
New , The Whole Game, previews the entire package development process.
New , System setup, has been carved out of the previous Introduction and gained more detail.
The chapter formerly known as Package structure has been expanded and split into two chapters, one covering package structure and state ().
New , The package within, demonstrates how to extract reusable logic out of data analysis scripts and into a package.
The sections Organising your functions and Code style, from which can automatically apply many of the rules.
The coverage of testing has expanded into three chapters: for various advanced topics.
Material around the NAMESPACE
file and dependency relationships has been re-organized into two chapters: gives practice instructions for using different types of dependencies in different settings.
New , Licensing, expands earlier content on licensing into its own chapter.
The chapter on C/C++ has been removed. It didnt have quite enough information to be useful, and since the first edition of the book, other resources have arisen that are better learning resources.
The Other components chapter has been removed.
The chapter on Git/GitHub has been reframed around the more general topic of software development practices (.
The very short inst
chapter has been combined into , with all the other directories that can be important in specific contexts, but that arent mission critical to all packages.
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italicShows text that should be replaced with user-supplied values or by values determined by context.
Tip
This element signifies a tip or suggestion.
Note
This element signifies a general note.
Warning
This element indicates a warning or caution.
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/oreillymedia/title_title.
If you have a technical question or a problem using the code examples, please send email to .
This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.
We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: Book Title by Some Author (OReilly). Copyright 2012 Some Copyright Holder, 978-0-596-xxxx-x.
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .
OReilly Online Learning
Note
For more than 40 years, OReilly Media has provided technology and business training, knowledge, and insight to help companies succeed.
Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. OReillys online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from OReilly and 200+ other publishers. For more information, visit https://oreilly.com