A free, open-source book that teaches R as a functional programming language. Five parts, 33 chapters, from first function call to metaprogramming and package development.
R descends from lambda calculus through Scheme and S. This book follows that lineage: everything is an expression, every expression returns a value, functions are values. Understanding the design makes vectorization, pipes, tidyverse, and ggplot2 click into place.
No programming experience is assumed.
- Foundations (ch. 1–9): computation models, vectors, functions, logic, algorithms
- Working with data (ch. 10–17): lists, data frames, strings, I/O, dplyr, tidy data, ggplot2
- Thinking functionally (ch. 18–23): closures, map/reduce, function factories, recursion, lazy evaluation
- The type system (ch. 24–27): S3/S7 objects, contracts, metaprogramming, building a DSL
- Going further (ch. 28–33): performance, R internals, C++/Rust/Python interop, packages, reproducibility
Spotted a typo, unclear explanation, or broken code? Open an issue or submit a pull request.
The book is built with Quarto.
quarto render
quarto preview # live reloadText: CC BY-NC-SA 4.0 · Code: MIT
@book{thinking-in-r,
author = {Colling, Gilles},
title = {Thinking in R},
year = {2026},
url = {https://gillescolling.com/thinking-in-r/},
doi = {10.5281/zenodo.18918794}
}If this book helped you, buying me a coffee is a nice way to say thanks.