R Workflow and Tools
r
workflow
rstudio
git
docker
jupyter
reproducibility
Editors, project setup, code style, Git and GitHub, containers, and helper packages for working in R with RStudio, Positron, or VS Code.
This guide gathers material on how to work with R day to day: choosing and configuring an editor, organizing projects, styling code, and using Git. Start with the editor and project sections, then add the style and Git guidance as your projects grow. Installing R itself is covered on the R page.
Editors and environments
- Command Palette, Posit — Posit documentation for the RStudio command palette, a searchable list of IDE commands.
- Run R on VSCode (2021 update) — Video on setting up and running R code in Visual Studio Code.
- Simple setup for R in VSCode instead of RStudio (Mac) — Video on configuring VS Code as an R development environment on a Mac.
- radian — Alternative R console that aims to be a more modern replacement for the default terminal console.
- Using R with Emacs and ESS — R-Bloggers article on the basics of running R from Emacs with the ESS package.
- Nvim-R for people who love R, vim, and keyboards — Blog post on writing R in Vim or Neovim with the Nvim-R plugin.
- How to install R on a Jupyter notebook — Storybench walkthrough of adding R to Jupyter notebooks and building a visualization.
- Configure Jupyter to work with R on a Mac — Steps for connecting Jupyter Notebook to R on a Mac with Homebrew.
- How to use R on Google Colaboratory — Medium article on running R in Google Colab; Medium may limit free reading.
- How to Install R on Ubuntu 20.04 — Linuxize instructions for installing R on Ubuntu 20.04.
- Setting up the R environment — OHDSI setup instructions, linked at the section on installing R build tools.
Projects and files
- Working Directories and Workspaces in the RStudio IDE — Posit support article on how RStudio chooses the working directory and handles saved workspaces.
- RStudio Projects and Working Directories: A Beginner’s Guide — Blog post introducing RStudio Projects and how to structure the files for a project.
- Structuring R projects — R-Bloggers post on organizing the folders and files of an R project.
- Best Coding Practices for R (2022) — Open-source book of recommended practices for writing R code (archived PDF).
- Code Structure — Chapter of Best Coding Practices for R on how to lay out code.
- How to set a variable in .Renviron — Posit Community answer on creating a .Renviron file in your home directory to set environment variables.
Code style
- Tidyverse style guide — The tidyverse team’s guide to naming, spacing, and layout in R code.
- Pipes, tidyverse style guide — Style guide chapter on how to write sequences of piped operations.
- styler — Package that reformats R code to follow the tidyverse style guide.
- lintr — Package that checks R code for style problems and likely errors.
Git and GitHub
- Happy Git and GitHub for the useR — Online book that explains how to connect R projects to Git and GitHub.
- Connect RStudio to Git and GitHub — Chapter of Happy Git and GitHub for the useR on linking an RStudio project to GitHub.
- GitHub Quick Tutorial for R and RStudio Projects — Video on setting up a GitHub account and using it to push and pull R code between computers.
- How to use Git and GitHub with R — Video on version control and syncing with GitHub from inside RStudio.
- Version Control with Git, R, and Positron — RPubs walkthrough of using Git with R in the Positron editor.
Reproducible environments and packages
- Rocker Project — Docker containers for running R.
- A docker tutorial for reproducible research — Tutorial on using Docker for reproducible research with R.
- litr: Writing R packages with literate programming — Project for writing an R package as a single R Markdown document.
- Make an R package in less than a minute! — Video showing how to create an R package with litr.
Keyboard shortcuts and tips
- RStudio Keyboard Shortcuts — R-Bloggers post on RStudio shortcuts and settings (archived copy).
- 6 Life-Altering RStudio Keyboard Shortcuts — R-Bloggers article on six RStudio shortcuts.
Helper packages and add-ins
| Package | What it does |
|---|---|
| pak | Installs R packages and their dependencies from the R console |
| here | Builds file paths relative to the project root so scripts run from any folder |
| reprex | Turns a small R example into text you can paste into a GitHub issue or Stack Overflow question |
| datapasta | Pastes copied data into R as code |
| addinslist | Lists RStudio addins and lets you install them from within RStudio |
| rsthemes | Adds full RStudio IDE and syntax themes |
| progress | Draws progress bars in the R terminal |
| annotater | Annotates package load calls such as library() in your scripts |