TL;DR I thought I could easily jump to a high standard (reproducibility), but I failed.

Some of you may have noticed that the knitr book is finally out. Amazon is offering a good price at the moment, so if you are interested, you’d better hurry up.
I avoided the phrase “Reproducible Research” in the book title, because I
did not want to take that responsibility, although it is related to
reproducible research in some sense. The book was written with knitr v1.3
and R 3.0.1, as you can see from my sessionInfo() in the preface.
Three months later, several things have changed, and I could not reproduce the book, but that did not surprise me. I’ll explain the details later. Here I have extracted the first three chapters, and released the corresponding source files in the knitr-book repository on GitHub. You can also find the link to download the PDF there. This repository may be useful to those who plan to write a book using R.
What I could not reproduce were not really important. The major change in
the recent knitr versions was the syntax highlighting commands, e.g.
\hlcomment{} is \hlcom{} now, and the syntax highlighting has been
improved by the highr package
(sorry, Romain). This change brought a fair amount of changes when I look at
git diff, but these are only cosmetic changes.
I tried my best to avoid writing anything that is likely to change in the future into the book, but as a naive programmer, I have to say sorry that I have broken two little features, although they may not really affect you:
- the preferred way to stop knitr in case of errors is to set the chunk
option
error = FALSEinstead of the package optionstop_on_error, which has been deprecated (Section 6.2.4); - for external code chunks (Section 9.2), the preferred chunk delimiter is
## ----instead of## @knitrnow;
Actually the backward-compatibility is still there, so they will not really break until a long time later.
With exactly the same software environment, I think I can reproduce the book, but that does not make much sense. Things are always evolving. Then there are two types of reproducible research:
- the “dead” reproducible research (reproduce in a very specific environment);
- the reproducible research that evolves and generalizes;
I think the latter is more valuable. Being reproducible alone is not the goal, because you may be reproducing either real findings or simply old mistakes. As Roger Peng wrote,
[…] reproducibility cannot really address the validity of a scientific claim as well as replication
Roger’s recent three blog posts on reproducible research are very worth reading. This blog post of mine is actually not quite relevant (no data analysis here), so I recommend my readers to move over there after you haved checked out the knitr-book repository.
Donate
As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.
-
Venmo:
@yihui_xie, or Zelle:xie@yihui.name -
Paypal
-
If you have a Paypal account, you can follow the link https://paypal.me/YihuiXie or find me on Paypal via my email
xie@yihui.name. Please choose the payment type as “Family and Friends” (instead of “Goods and Services”) to avoid extra fees. -
If you don’t have Paypal, you may donate through this link via your debit or credit card. Paypal will charge a fee on my side.
-
-
Other ways:
WeChat Pay (微信支付:谢益辉) Alipay (支付宝:谢益辉) 

When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.
Please feel free to email me if you prefer a different way to give. Thank you very much!
I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).