© Thomas Mailund 2017

Thomas Mailund, Functional Data Structures in R, https://doi.org/10.1007/978-1-4842-3144-9_3

3. Immutable and Persistent Data

Thomas Mailund

(1)Aarhus N, Denmark

What prevents us from implementing traditional imperative-language data structures in R is the immutability of data. As a general rule, you can modify environments—so you can assign to variables—but you cannot modify actual data. Whenever R makes it look like you are changing data, it is lying. When you assign to an element in a vector

x[i] <- v

the vector will look modified to you, but behind the curtain, R has really replaced the vector that x refers to with a new copy, identical to the old x except for element number i. It tries to do this efficiently, so it will ...

Get Functional Data Structures in R: Advanced Statistical Programming in R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.