Dynamic Documents with R and knitr
By Yihui Xie
Chapman and Hall/CRC – 2013 – 216 pages
Series: Chapman & Hall/CRC The R Series
The cut-and-paste approach to writing statistical reports is not only tedious and laborious, but also can be harmful to scientific research, because it is inconvenient to reproduce the results. Dynamic Documents with R and knitrintroduces a new approach via dynamic documents, i.e. integrating computing directly with reporting. A comprehensive guide to the R package knitr, the book covers examples, document editors, basic usage, detailed explanations of a wide range of options, tricks and solutions, extensions, and complete applications of this package.
The book provides an overview of dynamic documents, introducing the idea of literate programming. It then explains the importance of dynamic documents to scientific research and its impact on reproducible research. Building on this, the author covers basic concepts, common text editors that support knitr, and the syntax for different document formats such as LaTeX, HTML, and Markdown before going on to discuss core functionality, how to control text and graphics output, caching mechanisms that can reduce computation time, and reuse of source code. He then explores advanced topics such as chunk hooks, integrating other languages such as Python and awk into one report in the knitr framework, and useful tricks that make it easier to write documents with knitr. Discussions of how to publish reports in a variety of formats, applications, and other tools complete the coverage.
Suitable for both beginners and advanced users, this book shows you how to write reports in simple languages such as Markdown. The reports range from homework, projects, exams, books, blogs, and web pages to any documents related to statistical graphics, computing, and data analysis. While familiarity with LaTeX and HTML is helpful, the book requires no prior experience with advanced programs or languages. For beginners, the text provides enough features to get started on basic applications. For power users, the last several chapters enable an understanding of the extensibility of the knitr package.
"The book provides a systematic description of the package [knitr], including its concepts, design principles, and philosophy. It also has many examples, well-thought out advice, and useful tips and tricks. … The book is well written. It has introductory material useful for novices as well as advice for more seasoned users, all explained in conversational English without unnecessary technical jargon. … While I have been using Sweave and then knitr for several years, I still learned many new useful things from the book. … the book deserves a place on the bookshelves of both new and experienced R and TeX users."
—Boris Veytsman, TUGboat, Volume 35, 2014
"If you are looking to learn how to use knitr, this book is for you. There are a limited number of resources for learning knitr because the package is relatively new and the documentation produced by Xie is so good. … I think this book will continue to be the best resource about knitr …easy to understand … this is a great read and handy desk reference for the regular knitr user."
—Journal of Statistical Software, January 2014
Good and Bad Practices
A First Look
Extracting R Code
Plot Size in Output
Extra Output Options
The tikz Device
When to Update Cache
Cross Reference 79
Languages and Tools
Tricks and Solutions
Web Site and Blogging
Other R Packages