Advanced R, Second Edition

by Hadley Wickham

Published 1 October 2014

Advanced R helps you understand how R works at a fundamental level. It is designed for R programmers who want to deepen their understanding of the language, and programmers experienced in other languages who want to understand what makes R different and special.

This book will teach you the foundations of R; three fundamental programming paradigms (functional, object-oriented, and metaprogramming); and powerful techniques for debugging and optimising
your code.

By reading this book, you will learn:

  • The difference between an object and its name, and why the distinction is important
  • The important vector data structures, how they fit together, and how you can pull them apart using subsetting
  • The fine details of functions and environments
  • The condition system, which powers messages, warnings, and errors
  • The powerful functional programming paradigm, which can replace many for loops
  • The three most important OO systems: S3, S4, and R6
  • The tidy eval toolkit for metaprogramming, which allows you to manipulate code and control evaluation
  • Effective debugging techniques that you can deploy, regardless of how your code is run
  • How to find and remove performance bottlenecks

The second edition is a comprehensive update:

  • New foundational chapters: "Names and values," "Control flow," and "Conditions"
  • comprehensive coverage of object oriented programming with chapters on S3, S4, R6, and how to choose between them
  • Much deeper coverage of metaprogramming, including the new tidy evaluation framework
  • use of new package like rlang (http://rlang.r-lib.org), which provides a clean interface to low-level operations, and purr (http://purrr.tidyverse.org/) for functional programming
  • Use of color in code chunks and figures

    Hadley Wickham is Chief Scientist at RStudio, an Adjunct Professor at Stanford University and the University of Auckland, and a member of the R Foundation. He is the lead developer of the tidyverse, a collection of R packages, including ggplot2 and dplyr, designed to support data science. He is also the author of R for Data Science (with Garrett Grolemund), R Packages, and ggplot2: Elegant Graphics for Data Analysis.


This book offers solutions to all 284 exercises in Advanced R, Second Edition. All the solutions have been carefully documented and made to be as clear and accessible as possible. Working through the exercises and their solutions will give you a deeper understanding of a variety of programming challenges, many of which are relevant to everyday work. This will expand your set of tools on a technical and conceptual level. You will be able to transfer many of the specific programming schemes directly and will discover far more elegant solutions to everyday problems.

Features:

  • When R creates copies, and how it affects memory usage and code performance
  • Everything you could ever want to know about functions
  • The differences between calling and exiting handlers
  • How to employ functional programming to solve modular tasks
  • The motivation, mechanics, usage, and limitations of R's highly pragmatic S3 OO system
  • The R6 OO system, which is more like OO programming in other languages
  • The rules that R uses to parse and evaluate expressions
  • How to use metaprogramming to generate HTML or LaTeX with elegant R code
  • How to identify and resolve performance bottlenecks