What they forgot to teach you about R
2023-04-20
Description:
Do you use R in your daily work and research but you still feel your workflow isn’t as smooth as it could be? In this lecture, I will share with you my best tips from 8 years experience with R. We will cover those concepts and tricks that are often overlooked but can make a big difference. Whether you’re a beginner or more experienced R programmer, this lecture will enhance your workflow and help you write clean, reproducible and reusable code in R.
Summary
There are many good practice tools and tips that require minimal effort and that can be implemented in your workflow immediately. You can refer to the following checklist to see where you can still improve your project. For more details please have a look at the slides and the further resources linked below.
Project setup
- Keep all of your project files in one location and separate them into sub folders to have a good overview
- Make your project and R Studio Project
- Give your files meaningful names that are machine readable, human readable, and that work well with default ordering
Code
- Follow the standard structure of a code file
- Modularize your code and don’t write one single very long script
- Use save relative paths and avoid
setwd()
(This is easy if you use R Studio projects) - Follow a styleguide for your code (e.g. the tidyverse styleguide)
- Use the
lintr
and thestyler
package to help you with that
- Use the
Dependencies
- Manage your dependencies with
renv
to avoid your code from breaking the future
Further links
What they forgot to teach you about R book by Jenny Bryan and Jim Hester
Blogpost by Jenny Bryan on good project-oriented workflows
R best practice blogpost by Krista L. DeStasio
Book about coding style for R: The tidyverse style guide
The Turing way book General concepts and things to think about regarding reproducible research