Abstract
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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Strictly speaking, we can create side effects that affect data structures—we just have to modify environments. The reference class system, R6, emulates objects with a mutable state by updating environments, and we can do the same via closures. When we get to Chapter 4, where we will implement queues, I’ll introduce side effects of member queries, and there we will use this trick. Unless we represent all data structures by collections of environments, though, the method only gets us so far. We still need to build data structures without modifying data—we just get to remember the result in an environment we constructed for this purpose.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2017 Thomas Mailund
About this chapter
Cite this chapter
Mailund, T. (2017). Immutable and Persistent Data. In: Functional Data Structures in R. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-3144-9_3
Download citation
DOI: https://doi.org/10.1007/978-1-4842-3144-9_3
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-3143-2
Online ISBN: 978-1-4842-3144-9
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)