So far in this course, all of our coding has been done in Rmarkdown (.Rmd) documents. We did this to take advantage of the inline output feature of Rmarkdown documents, which is a great interactive way of working with R.
In my own work, I use Rmarkdown documents frequently, but usually in the later stages of analysis and write-up. For data wrangling, I tend to use .R scripts.
For a given analysis project, I organize all the relatied .R scripts and Rmarkdown documents into a single folder, and I utilize RStudio projects to codify this organization.
In this tutorial, I breifly discuss .R scripts and Rstudio projects.
A script is simply a text file that contains R code in it. These files are given a .R extension to identify them as R scripts.
Scripts can contain analysis code, custom made functions, or both. What you choose to do with a script is really up to you. The only guidance I will give is that if your script becomes long, say approaching 200 lines, it’s probably time to reorganize your code and break it up into smaller scripts or functions.
In the next tutorial, we will do our coding in a script to help you get familiar with coding in that context. It’s nearly identical to the coding in Rmarkdown, with just a few minor differences to be aware of.
Whenever you begin an analysis effort that is anything other than single-session scratch work, I highly recommend you start an RStudio project to organize your efforts. It will pay future dividends to make this a habit even before you understand all the nuances of Rstudio project.
I lieu of discussing projects in general, we will get more familiar with them by working through the Capstone assignment together.
For an introduction to projects, here is an excellent article written by RStudio: Using R Studio Projects.
R4DS - Chapter 6 - Workflow: scripts
R4DS - Chapter 8 - Workflow: projects
R4DS - Chapter 27 - R Markdown