1 Introduction

The traditional way to write a report, manuscript or thesis is to run the analyses in R or some other software and then copy the figures, tables etc. into a word processor. Then you find an error in the code or data and need to repeat the process. Repeatedly.

This is very inefficient and error prone: there is a better way.

R Markdown lets you have the code and the text in one document. If the code or the data are updated, new versions of the figures and tables are automatically generated and inserted into the corrected document. This is a much more reproducible process.

This book is written with R Markdown.

1.1 Reading

Perkel (2022) Cut the tyranny of copy-and-paste with these coding tools, Nature 603, 191-192 doi: https://doi.org/10.1038/d41586-022-00563-z

1.2 Organisation of this book

First Steps with R Markdown shows you how to create an R Markdown document, edit it, add figures and tables, and render it as a finished document.

Towards a Thesis shows you how author a manuscript, report or thesis in R markdown by adding citations and cross-references to figures and tables.

Fixing Problems The final section has some trouble shooting suggestions.

1.3 R markdown and Quarto

Quarto is the next generation of R Markdown, but R Markdown is not going away. If you know how to use R markdown, you know how to use quarto as almost any R Markdown document should also work with quarto.

There are several improvements in quarto over R Markdown which make it easier to use.

  • No need to remember different behaviour and capabilities of the rmarkdown and bookdown etc packages.

  • Simplified cross-references.

  • Better support for multiple programming languages.

If you cannot install quarto, or it won’t work, then use R Markdown instead.

Before you start

You will need to have installed

  • RStudio (version 2022.2 or newer)
  • R
  • rmarkdown and bookdown R packages (install.packages("bookdown"))