Reproducible Research with R and R Studio: 2nd Edition (Paperback) book cover

Reproducible Research with R and R Studio

2nd Edition

By Christopher Gandrud

Chapman and Hall/CRC

323 pages | 31 B/W Illus.

Purchasing Options:$ = USD
Paperback: 9781498715379
pub: 2015-06-11
SAVE ~$15.79
Paperback: 9781138469648
pub: 2017-10-02
SAVE ~$41.00
eBook (VitalSource) : 9781315382548
pub: 2018-09-03
from $37.98

FREE Standard Shipping!


All the Tools for Gathering and Analyzing Data and Presenting Results

Reproducible Research with R and RStudio, Second Edition brings together the skills and tools needed for doing and presenting computational research. Using straightforward examples, the book takes you through an entire reproducible research workflow. This practical workflow enables you to gather and analyze data as well as dynamically present results in print and on the web.

New to the Second Edition

  • The rmarkdown package that allows you to create reproducible research documents in PDF, HTML, and Microsoft Word formats using the simple and intuitive Markdown syntax
  • Improvements to RStudio’s interface and capabilities, such as its new tools for handling R Markdown documents
  • Expanded knitr R code chunk capabilities
  • The kable function in the knitr package and the texreg package for dynamically creating tables to present your data and statistical results
  • An improved discussion of file organization, enabling you to take full advantage of relative file paths so that your documents are more easily reproducible across computers and systems
  • The dplyr, magrittr, and tidyr packages for fast data manipulation
  • Numerous modifications to R syntax in user-created packages
  • Changes to GitHub’s and Dropbox’s interfaces

Create Dynamic and Highly Reproducible Research

This updated book provides all the tools to combine your research with the presentation of your findings. It saves you time searching for information so that you can spend more time actually addressing your research questions. Supplementary files used for the examples and a reproducible research project are available on the author’s website.


"The first edition of Reproducible Research with R and RStudio was an invaluable companion in the early stages of my journey, and I trust that the second edition will be equally useful to aspiring data analysts."

MAA Reviews, July 2015

Praise for the First Edition:

"… a very practical book that teaches good practice in organizing reproducible data analysis and comes with a series of examples. … an extremely valuable overview of the current capabilities of R, RStudio, and related software tools for reproducible research. I recommend this book to anyone who wants to learn more about these fascinating tools."

Biometrical Journal, 2014

"Gandrud has written a great outline of how a fully reproducible research project should look from start to finish, with brief explanations of each tool that he uses along the way. … the readers who will get the most use from this book are those already working in R and just need a way to organize their work. That being said, advanced undergraduate students in mathematics, statistics, and similar fields as well as students just beginning their graduate studies would benefit the most from reading this book. Many more experienced R users or second-year graduate students might find themselves thinking, ‘I wish I’d read this book at the start of my studies, when I was first learning R!’ … a good text for beginning graduate students or advanced undergraduate students who are just starting to do technical research. … This book could be used as the main text for a class on reproducible research …"

The American Statistician, November 2014

"Three recent books have significantly influenced how I use R in reproducible work: Dynamic Documents with R and knitr by Yihui Xie, Reproducible Research with R and RStudio by Christopher Gandrud, and Implementing Reproducible Research edited by Victoria Stodden, Friedrich Leisch, and Roger D. Peng … I recommend all three books to R users at any level. There really is something here for everyone."

—Richard Layton, PhD, PE, Rose-Hulman Institute of Technology, Terre Haute, Indiana, USA

Table of Contents

Getting Started

Introducing Reproducible Research

What Is Reproducible Research?

Why Should Research Be Reproducible?

Who Should Read This Book?

The Tools of Reproducible Research

Why Use R, knitr/rmarkdown, and RStudio for Reproducible Research?

Book Overview

Getting Started with Reproducible Research

The Big Picture: A Workflow for Reproducible Research

Practical Tips for Reproducible Research

Getting Started with R, RStudio, and knitr/rmarkdown

Using R: the Basics

Using RStudio

Using knitr and rmarkdown: the Basics

Getting Started with File Management

File Paths and Naming Conventions

Organizing Your Research Project

Setting Directories as RStudio Projects

R File Manipulation Commands

Unix-Like Shell Commands for File Management

File Navigation in RStudio

Data Gathering and Storage

Storing, Collaborating, Accessing Files, and Versioning

Saving Data in Reproducible Formats

Storing Your Files in the Cloud: Dropbox

Storing Your Files in the Cloud: GitHub

RStudio and GitHub

Gathering Data with R

Organize Your Data Gathering: Makefiles

Importing Locally Stored Data Sets

Importing Data Sets from the Internet

Advanced Automatic Data Gathering: Web Scraping

Preparing Data for Analysis

Cleaning Data for Merging

Merging Data Sets

Analysis and Results

Statistical Modelling and knitr

Incorporating Analyses into the Markup

Dynamically Including Modular Analysis Files

Reproducibly Random: set.seed

Computationally Intensive Analyses

Showing Results with Tables

Basic knitr Syntax for Tables

Table Basics

Creating Tables from Supported Class R Objects

Showing Results with Figures

Including Non-Knitted Graphics

Basic knitr/rmarkdown Figure Options

Knitting R’s Default Graphics

Including ggplot2 Graphics

JavaScript Graphs with googleVis

Presentation Documents

Presenting with knitr/LaTeX

The Basics

Bibliographies with BibTeX

Presentations with LaTeX Beamer

Large knitr/LaTeX Documents: Theses, Books, and Batch Reports

Planning Large Documents

Large Documents with Traditional LaTeX

knitr and Large Documents

Child Documents in a Different Markup Language

Creating Batch Reports

Presenting on the Web and Other Formats with R Markdown

The Basics

Further Customizability with rmarkdown

Slideshows with Markdown, rmarkdown, and HTML

Publishing HTML Documents Created by R Markdown


Citing Reproducible Research

Licensing Your Reproducible Research

Sharing Your Code in Packages

Project Development: Public or Private?

Is it Possible to Completely Future Proof Your Research?



About the Author

Christopher Gandrud is a postdoctoral researcher in the Fiscal Governance Centre at the Hertie School of Governance. His research focuses on the international political economy of public financial and monetary institutions as well as applied social science statistics and software development. He has published many articles in peer-reviewed journals, including the Journal of Common Market Studies, Review of International Political Economy, Political Science Research and Methods, Journal of Statistical Software, and International Political Science Review. He earned a PhD in quantitative political science from the London School of Economics.

About the Series

Chapman & Hall/CRC The R Series

Learn more…

Subject Categories

BISAC Subject Codes/Headings:
MATHEMATICS / Probability & Statistics / General