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 https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005510. 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) https://www.tidyverse.org/blog/2017/12/workflow-vs-script/
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 https://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. https://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 https://rstudio.github.io/renv/articles/renv.html
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 https://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 https://rmarkdown.rstudio.com/lesson-1.html 
8. Check out the great materials at @openscapes by @juliesquid and @ecodatasci for other helpful tips on creating open and reproducible science using #rstats #ropensci https://www.openscapes.org  https://eco-data-science.github.io 
You can follow @DanOvand0.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: