# 1 Preface

Welcome to the work-in-progress 2nd edition of Advanced R. This preface describes the major changes that I have made to the book.

The 2nd edition has been published in colour, which as well as improving the syntax highlighting of the code chunks, has considerably increased the scope for helpful diagrams. I have taken advantage of this and included many more diagrams throughout the book.

## 1.1 rlang

A big change since the first edition of the book is the creation of the rlang package, written primarily by Lionel Henry. The goal of this package is to provide a clean interface to low-level data structures and operations. I use this package in favour of base R because I believe it makes easier to understand how the R language works. Instead of struggling with the incidentals of functions that evolved organically over many years, the more consistent rlang API makes it easier to focus on the big ideas.

In each section, I’ll briefly outline the base R equivalents to rlang code. But if you want to see the purest base R expression of these ideas, I recommend reading the first edition of the book, which you can find online at http://adv-r.had.co.nz.

Overall, rlang is still a work in progress, and much of the API continues to mature. However, the code used in this book is part of the rlang’s testing process and will continue to work in the future. You can also see our confidence in the stability of rlang functions with the lifecycle badges at the documentation.

## 1.2 Foundations

• Environments: more pictures. Much improved discussion of frames and how they relate to the call stack.

• New chapter on “Names and values” that helps you form a better mental of <-, and to better understand when R makes copies of existing data structures. Understanding the distinction between names and values is important for functional programming, and understanding when R makes copies is critical for accurate performance predictions.

• Exceptions and debugging has been split into two chapters, “debugging” and “conditions”. The contents of conditions has been expanded. The section of defensive programming has been removed, because discussing type stability is more natural in the context of functional programming, and programming with NSE is not the challenge it once was (now that tidy evaluation exists).