ABSTRACT

The second chapter explains the distinction between an object and its name. This distinction is important, as it helps:

More accurately predicting the performance and memory usage of R code.

Writing faster code by avoiding accidental copies, a major source of slow code.

Better understanding R’s functional programming tools.

In section “Binding basics”, we introduce the distinction between names and values, and how bindings, or references, between a name and a value are created. Then, in “Copy-on-modify”, we learn when R makes a copy and how to use tracemem to figure out when a copy actually occurs. We also learn about the implications for different R objects. In “Object size” we explore how much memory an object occupies. “Modify-in-place” describes two exceptions to copy-on-modify: environments and values with a single name are actually modified in place. Lastly, we conclude this chapter with a discussion of the garbage collector, in “Unbinding and the garbage collector”.