This document is the support of the course Working with R.

It can be downloaded as a PDF file.

It proposes an organization of the work around R and RStudio in order to, beyond statistics, write documents efficiently with R Markdown, in various formats (memos, scientific articles, student theses, books, slideshows), create a web site and online R applications (Shiny), produce packages and use R for teaching. It complements Reproducible Research with R and R Studio (Gandrud 2015) with a more hands-on approach, with ready-to-use solutions.

Optimizing the use of the many tools available is covered in detail: rmarkdown, bookdown and blogdown for writing, roxygen2, testthat and pkgdown for packages, source control with git and GitHub, continuous integration with GitHub Actions and Codecov. Examples are presented at each step, and the necessary code is provided.

Chapter 1 is dedicated to the installation of the necessary tools: R, git and LaTeX. Chapter 2 details some advanced aspects of using R: the different languages, the environments, the performance of the code. The basic use of R is not covered here: good courses are suggested. Chapter 3 presents source control with git and GitHub.

Chapter 4 shows how to write simple (articles) or complex (books) documents with R Markdown, integrating the data, the code to process them and the text to present them. Chapter 5 presents a step-by-step method to efficiently create a package. Chapter 6 introduces the use of continuous integration to automatically produce documents, verify package code and produce package vignettes. Chapter 7 introduces Shiny to develop R interactive applications. Finally, chapter 8 introduces the tools for teaching R.


Package names are in bold in the text, for example: ggplot2.

The identifier used on GitHub is noted GitHubID. Project names are the same as their GitHub repository, noted RepoID.

The sign |> in the code of the examples indicates that the rest of the code should be on the same line, but is cut for the formatting of this document. Its use is limited to YAML configuration files, mostly in chapter 6. In all other cases, the code can be copied directly.