© Thomas Mailund 2017

Thomas Mailund, Functional Programming in R, 10.1007/978-1-4842-2746-6_2

2. Pure Functional Programming

Thomas Mailund

(1)Aarhus N, Denmark

A pure function is a function that behaves like a mathematical function: it maps values from one space to another, the same value always maps to the same result, and there is no such thing as a side effect in a mathematical function.

The level to which programming languages go to ensure that functions are pure varies, and R does precious little in this regard. Because values are immutable, you have some guarantee about which side effects functions can have, but not much. Functions can modify variables outside their scope, for example, they can modify global variables. They can print or plot ...

Get Functional Programming in R: Advanced Statistical Programming for Data Science, Analysis and Finance now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.