Fall is here and a lot of students are starting their journey as #rstats users. This can be tough, especially with all the barriers to learning that 2020 is throwing at us. Here are some tips (almost all from @JennyBryan!) I wish I’d followed from the start of my #rstats career
Beginning #rstats users sometimes focus on the mechanics of R and don’t get around to establishing some best practices that will set you up for writing more efficient and reproducible code. These all will make your life easier in the long run, I promise! #openscience
1. Develop a project-oriented workflow. Decide on a common file structure and stick with it for every project. Here’s what I use, based on this great paper journals.plos.org/ploscompbiol/a…. That way, you always know where to find files in any project
2. Purge setwd from your #rstats code! Using #rstudio projects with project-oriented workflows ensures your working directory is correct and that your code will work for future you and your collaborators without using setwd (from @JennyBryan) tidyverse.org/blog/2017/12/w…
3. Get rid of hard-coded file paths! read.csv(“~/my/computer/data/data.csv”) will only work on your current computer . Using read.csv(here::here(“data”,”data.csv”)) will work for future you and collaborators on any platform github.com/r-lib/here ( @allison_horst )
4. Use a version control system like git + GitHub. It’s great for collaboration & reproducibility, and having a time machine for your code when you inevitably break everything night before a major deadline is a game changer. happygitwithr.com
5. Manage package dependencies with renv. We’ve all been there: you decide to update packages and suddenly your code for tomorrow’s deadline is broken! renv helps you and your collaborators manage package versions to keep things running smoothly rstudio.github.io/renv/articles/…
6. Pick a style guide and stick with it. e.g. I use snake_case since it reads well, avoids confusing case-sensitive variable names, and is easy to program with. e.g. finding and saving all objects that end with “_plot" is super easy style.tidyverse.org
7. Make friends with #rmarkdown. You put a lot of time and effort into #rstats homework. Doing them in R Markdown means that you can easily reproduce your steps when you want to actually put what you learned into practice someday down the road rmarkdown.rstudio.com/lesson-1.html