R programming books split into two camps: the ones that teach the tidyverse way of working with data, and the ones that teach R as a language. You will want one from each camp eventually, but which comes first depends on whether you are here to analyze data or to write code that other people run.
We picked nine, from R for Data Science and Advanced R to the statistical modeling texts, and ran sample code from seven of them. Six are free to read online, so the real question is which ones to own in print. We checked every listing against Amazon US in November 2026 and ran the book code on R 4.6.2 under Ubuntu 24.04.
Which R book should you read first?
For most people, start with R for Data Science. It is free online, it teaches the tidyverse packages that most R jobs use, and its code ran on current packages in our test with nothing worse than a few new messages. Pick a different first book only if one of these describes you:
- You have never programmed at all: Hands-On Programming with R teaches functions and objects through three small games.
- You need statistics and R together for a course: The Book of R, 2nd Edition covers both in one 936-page volume.
- You already write R and want to understand it: Advanced R explains environments, closures and metaprogramming.
- Your job is predictive models: Tidy Modeling with R follows straight on from R for Data Science.
- You want the statistics behind the models: An Introduction to Statistical Learning runs a lab in R at the end of every chapter.
If you work in Python and only need R for one project, skip the language books entirely. Read R for Data Science online, then go back to our data science books for Python users for the rest of your shelf.
How did we pick and test these nine?
Every pick had to teach R itself or use R as the main language for its examples, and it had to be buyable new on Amazon in the US. Each one then went through the same checks before it made the list:
- The edition we link is the newest one in print, and the cover, ISBN and Amazon listing all match it.
- The coverage we describe comes from the publisher page, the book site the authors run, or the code repository for the book.
- Where a book has a free legal online edition, we link the copy the authors host themselves.
- Where a book has public example code, we ran a sample of it on a clean R install and kept the real output.
The test machine was an Ubuntu 24.04 VM with R from the CRAN apt repository and packages from the Posit binary mirror. That is the setup most readers will have if they install R today, so any breakage we hit is breakage you’d hit too. The capture below shows the R build and the package versions the book code ran against:

Two books got no code run. The Book of R ships its code as a zip from the publisher, and R in Action keeps its scripts on GitHub; both are base R and tidyverse code that the other runs already exercise, so we judged them on the published table of contents instead. Prices are bands from the Amazon catalog on the day we checked, because they move weekly.
How do the R books compare?
The table lines the nine up. “Our code run” is what happened when we ran example code from the book on the current release; “free online” means the full text, not a sample chapter.
| Book | Edition, year | Pages | Level | Free online | Our code run |
|---|---|---|---|---|---|
| R for Data Science | 2nd, 2023 | 576 | Beginner | Yes | Ran, new dplyr messages |
| Hands-On Programming with R | 1st, 2014 | 250 | Absolute beginner | Yes | Ran, qplot() deprecated |
| The Book of R | 2nd, 2025 | 936 | Beginner to intermediate | Sample chapter | Not run |
| R in Action | 3rd, 2022 | 656 | Beginner to intermediate | Preview only | Not run |
| Advanced R | 2nd, 2019 | About 600 | Advanced | Yes | Ran clean |
| R Packages | 2nd, 2023 | 381 | Intermediate | Yes | Ran clean, check passed |
| Tidy Modeling with R | 1st, 2022 | 381 | Intermediate | Yes | Ran clean |
| An Introduction to Statistical Learning | 2nd, 2021 | 622 | Intermediate | Yes, PDF | Ran, matches the book |
| Statistical Rethinking | 2nd, 2020 | 612 | Intermediate to advanced | Chapters 1 and 2 | Package not on CRAN |
Read the last column before the page counts. A few patterns there decide most purchases:
- Six of the nine have the full text free online, so you can try the style before you pay.
- None of the seven code runs failed outright, and the only real breakage was a package that isn’t on CRAN.
- The older the book, the more warnings you will read, so the 2014 title needs the most patience.
R holds its code together better than most ecosystems. The tidyverse marks old functions as superseded or deprecated for years before it removes them, which is why a 2014 book still runs. What changes is the noise around the output, and that is the part a beginner cannot tell apart from a real error.
1. R for Data Science (2nd Edition)
Hadley Wickham, Mine Çetinkaya-Rundel and Garrett Grolemund wrote the book most R users now start with, and the 2023 edition is the one to get.

Its parts follow a real project: visualize, transform, import, program and communicate. Modeling is in the diagram but not the book, and the authors send you to Tidy Modeling with R for it. The second edition switched its examples to the native |> pipe and recommends R 4.2.0 or later. The full book is free at r4ds.hadley.nz, and that site is rebuilt against current packages, so its printed output lines up with what you will see today.
We ran the flights summary from the data transformation chapter and the penguin scatter plot from chapter 1. Both worked, but dplyr now prints a longer message after summarize() that points you to the newer .by argument:

The two “Removed 2 rows” warnings are expected, because two penguins in the data have no measurements. Skip this book if you already use dplyr and ggplot2 daily, since most of it will be review. At about $40 to $45 against an $80 list price, the paperback is worth buying mainly to work the exercises away from a screen.
2. Hands-On Programming with R
Garrett Grolemund wrote this one for people who have never written a function in any language, and it still does that job better than anything newer.
The book teaches through three projects: a weighted die, a deck of playing cards and a slot machine. Along the way you learn objects, subsetting, environments, loops and vectorized code, which is the programming half that data books skip. It is free to read online under a Creative Commons licence.
The book dates from 2014, and the first project shows its age. The dice function ran fine, but every plot in the book uses qplot(), which ggplot2 deprecated in 3.4.0. The top half of this capture is that run; the bottom half is Advanced R code, covered at pick 5:

The plots still saved, so the warning costs you nothing while you learn. Skip it if you can already write a loop and a function in another language, because the pace will feel slow. It is the cheapest pick here at about $25 to $30, though Amazon listed it as low stock.
3. The Book of R, 2nd Edition
Tilman Davies teaches R and introductory statistics in one book, and the second edition is the newest title on this list.
Its five parts run in course order, so you can follow it like a semester:
- Part I covers the language: vectors, matrices, lists, data frames and plotting basics.
- Part II covers programming: functions, conditions, loops and error handling.
- Parts III and IV cover probability, confidence intervals, hypothesis tests, ANOVA and regression.
- Part V covers advanced graphics, including the grammar of graphics and interactive 3D plots.
No Starch says the new edition adds nearly 100 pages, with more on plotting, pipes and reading and writing files. The publisher page offers the code and exercise solutions as a download, plus one free sample chapter. We did not run that code, so we cannot vouch for it the way we can for the free books. At 936 pages and about $50 to $55, it’s a lot of book; skip it if you only want the tidyverse workflow, which R for Data Science teaches faster.
4. R in Action, Third Edition
Robert Kabacoff wrote the broadest single reference here, and it suits analysts who want one book on the desk rather than a series.
Manning lists the 2022 edition as adding tidyverse and ggplot2 coverage plus machine learning examples for clustering, classification and time series. The rest spans data cleaning, regression, hypothesis tests, principal components, forecasting, dynamic reports, debugging and building packages. The scripts are in the RiA3 repository on GitHub, organized by chapter.
Breadth is also the trade-off: each topic gets a chapter where the specialist books below give it a whole volume. Skip it if you will end up buying Tidy Modeling with R or ISLR anyway. Amazon showed it as low stock at about $50 to $55, close to its $60 list price, so the discount is small.
5. Advanced R, Second Edition
Hadley Wickham wrote Advanced R for people who already use R and want to know why it behaves the way it does.
The second edition is free at adv-r.hadley.nz, and a separate solutions book works through the exercises. Its parts build on each other in this order:
- Foundations covers names and values, environments, control flow and conditions.
- Functional programming covers functionals, function factories and function operators with purrr.
- Object-oriented programming compares the S3, S4 and R6 systems.
- Metaprogramming explains tidy evaluation with rlang, the part that makes dplyr code work.
- Techniques closes on debugging, measuring performance and rewriting slow code in C++.
The new chapters on names and values and control flow, plus the rewritten conditions chapter, are the ones most worth reading even if you skim the rest, because they explain the behaviour behind most surprising R bugs.
Its code held up best of all in our run, shown in the lower half of the capture at pick 2. Two names pointed at the same memory address until one was modified, and tracemem() then reported the copy, which is exactly the copy-on-modify behaviour chapter 2 describes. obj_size(1:1e6) printed 680 B, because R stores that sequence as a compact ALTREP object instead of a million integers.
Do not start here. The book assumes a few months of everyday R, and the metaprogramming part only makes sense once you have been confused by tidy evaluation yourself. The paperback ran about $60 to $65 when we checked, and publisher and Amazon page counts differ slightly, landing near 600 either way.
6. R Packages, 2nd Edition
Hadley Wickham and Jennifer Bryan wrote the guide to turning loose scripts into a package that installs, documents itself and passes checks.
Its “whole game” chapter builds a tiny package called regexcite from start to finish before the rest of the book explains each piece. We followed it with the current usethis and devtools: create_package(), an MIT licence, roxygen documentation and a full devtools::check(). The check finished clean in about 11 seconds:

One change has landed since print: devtools 2.5.0 deprecated install_github() in favour of pak::pak(), so expect that warning wherever older material installs from GitHub. The full text is free at r-pkgs.org. Skip it if your R code never leaves your own laptop. Amazon showed low stock at about $40 to $45.
7. Tidy Modeling with R
Max Kuhn and Julia Silge maintain the tidymodels packages, and this is their book on fitting, tuning and comparing models with them.
Its 21 chapters fall into three parts: tidymodels basics built around an Ames housing dataset, resampling and tuning, and further topics such as dimension reduction and explaining models. It assumes you know dplyr and ggplot2 already, and the authors point you to R for Data Science first. The online edition at tmwr.org is free.
We ran the chapter 6 linear model on the Ames data. It fit cleanly on the current tidymodels release, with no warnings beyond the usual conflicts block:

Read the conflicts block before you start: recipes::step() masks stats::step(), and the book has you call tidymodels_prefer() to settle that. The online text still writes the older %>% pipe, while our script used |>, and both worked. Skip it if you want the statistics behind the models, which ISLR explains better. It was about $35 to $40 and low in stock.
8. An Introduction to Statistical Learning with Applications in R
Gareth James, Daniela Witten, Trevor Hastie and Robert Tibshirani wrote the standard first textbook on statistical learning, and every chapter ends with an R lab.

The 2021 second edition added deep learning, survival analysis and multiple testing to the regression, classification, resampling, trees and SVM chapters. The authors offer a free PDF on statlearning.com, a corrected June 2023 version, alongside a Python edition from 2023. It also appears in our machine learning books list.
We ran the chapter 3 lab, a regression of median house value on lstat in the Boston data that ships in the ISLR2 package. The numbers are the ones printed in the chapter:

An intercept of 34.55, a slope of -0.95 and an R-squared of 0.544 mean the lab still teaches exactly what the text says. The math is gentler than the authors’ Elements of Statistical Learning, but you still need comfort with algebra and basic probability; our math and statistics books for machine learning cover that gap. Skip the print copy if the PDF works for you. Amazon showed limited stock at about $55 to $60.
9. Statistical Rethinking, 2nd Edition
Richard McElreath teaches Bayesian statistical modeling with R and Stan, and the book won the 2023 De Groot Prize from the International Society for Bayesian Analysis.
The second edition leans on causal diagrams, priors and multilevel models, and it ends with models that go beyond GLMs. McElreath posts a free lecture series on YouTube that follows the book, and he has said a third edition is in progress with no date. Until then the 2020 edition is the one to buy.
This was the only pick where the code did not just run. The rethinking package that goes with the book is not on CRAN, and its README says it never will be. The README route for its “slim” branch without Stan, devtools::install_github(), failed for us because current devtools wants the remotes package and warns that the function is deprecated. This sequence, run in R, worked:
install.packages(c("coda", "mvtnorm", "devtools", "loo", "dagitty"))
install.packages("remotes")
remotes::install_github("rmcelreath/rethinking@slim")
With the package in place, the chapter 2 globe-tossing model gave the same answer as the text:

A posterior mean of 0.67 with an 89% interval of 0.42 to 0.92 matches chapter 2. Plan the install around the chapters you are reading, because the README splits the package into two builds:
- The slim branch installs in under a minute and runs the
quap()models through chapter 8. - The MCMC chapters need the full package plus cmdstanr and a C++ toolchain, which we did not install.
Starting on the slim build is the sensible order, since the first eight chapters are where the book builds your intuition for priors and posteriors before any sampler appears. Skip the book if you want frequentist methods for a course or a job that expects p-values, and know it’s the priciest pick here at about $110 to $115, more than twice the cost of most of the others.
How do you set up R to follow these books?
Install R from the CRAN Ubuntu repository rather than the distro package, because the Ubuntu archive lags behind the current release. These commands, based on the CRAN Ubuntu instructions, are the ones we ran on the test VM:
sudo apt update -qq
sudo apt install --no-install-recommends software-properties-common dirmngr wget
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
sudo apt install --no-install-recommends r-base r-base-dev
Several of the book packages link against system libraries for web requests, XML, fonts and images, so add the development headers next:
sudo apt install libcurl4-openssl-dev libssl-dev libxml2-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev libgit2-dev
By default R on Linux compiles every CRAN package from source, and the tidyverse plus tidymodels takes a long time that way. The Posit public package manager serves prebuilt Linux binaries instead. Open your R profile:
vim ~/.Rprofile
Add these two lines. The noble path matches Ubuntu 24.04, so change it if you’re on another release:
options(repos = c(CRAN = "https://packagemanager.posit.co/cran/__linux__/noble/latest"))
options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"])))
Our first package install failed with 'lib = "/usr/local/lib/R/site-library"' is not writable. Interactive R offers to create a personal library at that point, but Rscript can’t ask, so it just stops. Create the folder yourself, where the last part is your R major and minor version (on an arm64 machine the folder starts with aarch64 instead), and the install goes through:
mkdir -p ~/R/x86_64-pc-linux-gnu-library/4.6
Rscript -e 'install.packages(c("tidyverse","nycflights13","palmerpenguins","tidymodels","devtools","ISLR2","lobstr","rlang"))'
With binaries, all eight packages and their dependencies installed in 52 seconds. By the end of our tests, with the rethinking package and its dependencies added, the personal library came to 332 MB:

If you’d rather work in RStudio than a terminal, our guide to R and RStudio Server on Ubuntu and Debian adds the IDE on top of this, and there is a matching guide for Rocky Linux and AlmaLinux.
Does code from older R books still run?
Mostly yes, with warnings. Second-hand copies of the first R for Data Science and older course notes are everywhere, so we also ran first-edition idioms on the current tidyverse. The old summarise_at() with funs() still returned the right means, under a deprecation warning:

When you see one of these in an old book, swap in the modern form below. Each line is something we ran or saw in the test, so you can check it on your own install:
gather()andspread()still run without a warning, andpivot_longer()gives the same rows in a different order.summarise_at(vars(mpg, hp), funs(mean))warns, andsummarise(across(c(mpg, hp), mean))returns identical numbers.qplot()warns that it was deprecated in ggplot2 3.4.0, but the plot is still drawn.devtools::install_github()warns and needs the remotes package;pak::pak()is the suggested replacement.
One change catches newer books too. R 4.5.0 added its own penguins dataset to base R, with shorter column names than the palmerpenguins package that R for Data Science and many tutorials load:

Both have 344 rows, but base R calls the flipper column flipper_len where the book says flipper_length_mm. If you skip library(palmerpenguins), R still finds a penguins dataset, so expect the plots to complain about a missing column rather than a missing dataset, which is a confusing error to meet on page one. Load the package first and the book code works as printed.
What does a first month with R look like?
Buying four of these at once is a good way to finish none. We’d run it as a plan where each step ends with something you can check before you move on:
- R and the tidyverse install with binaries, and
library(tidyverse)prints the attach banner without errors. - You have finished the first section of R for Data Science online and can filter, group and summarize the flights data from memory.
- If writing your own functions still feels shaky, you’ve worked through the dice project in Hands-On Programming with R.
- You’ve picked one direction and its book: Tidy Modeling with R or ISLR for models, Statistical Rethinking for Bayesian work, R Packages for sharing code.
- Advanced R stays on the list for later, once tidy evaluation has confused you at least once.
Only buy print for the books you will keep open next to the keyboard, since most of this shelf is free to read. If you end up pulling data out of databases for your R work, our SQL books list is the natural next stop, and the general programming books round-up covers the habits no R book teaches.






