One of the basic steps to reproducibility and modern workflows in data analysis is to keep everything contained in a single location. In RStudio, this is done with R Projects. Please read all of this section from the introduction workshop to learn about R Projects and how they help keep things self-contained. You don’t need to do any of the exercises or activities.
There are several ways to organise a project folder. We’ll be using the structure from the package prodigenr. The project setup can be done by either:
Using RStudio’s New Project menu item: “File -> New Project -> New Directory”, scroll down to “Scientific Analysis Project using prodigenr” and name the project “AdvancedR3” in the Directory Name, saving it to the “Desktop” with Browse. Note: You might need to restart RStudio if you don’t see this option.
Or, running the command prodigenr::setup_project("~/Desktop/AdvancedR3") (or other location like Documents) in the R Console and manually switching to it using: File -> Open Project and navigating to the project location.
When the RStudio Project opens up again, run these commands in the R Console to finish the setup:
Console
# Add Git to the projectprodigenr::setup_with_git()# Create a `functions.R` file in the `R/` folderusethis::use_r("functions", open =FALSE)# Ignore this file that gets created by some usethis functionsusethis::use_git_ignore(".Rbuildignore")# Set some project options to start fresh each timeusethis::use_blank_slate("project")
Here we use the usethis package to help set things up. usethis is an extremely useful package for managing R Projects and we highly recommend checking it out more to see how you can use it in your own work.
11.1 R Markdown and Quarto
We teach and use R Markdown/Quarto because it is one of the very first steps to being reproducible and because it is a very powerful tool to doing data analysis. You may have heard of or used R Markdown since we’ve used it in both the introduction and intermediate workshops. However, you might not have heard of or used Quarto.
Quarto is a next generation version of R Markdown and chances are, if you use a fairly recent version of RStudio, you are already using it without realizing it. That’s because Quarto uses the same Markdown syntax as R Markdown. The only difference is that with Quarto, you can create more types of output documents (like books, websites, slides), you have more options for customization, and it’s easier to do and learn than R Markdown. So, for this workshop, we will use Quarto to create a report that includes the analysis we will do over the workshop.
Please do these two tasks:
Please read over the R Markdown/Quarto section of the introduction workshop. If you use R Markdown or Quarto already, you can skip this step.
In the R Console while inside the AdvancedR3 project, run the function to create a new Quarto file called learning.qmd in the doc/ folder.