5  🏃‍♂️Running Code

5.1 Options

I’ll cover two primary ways that you can execute R (R Core Team 2021) code in RStudio (RStudio Team 2020):

  1. script (R Core Team 2021) 🫤
  2. quarto (Allaire et al. 2022) 🤩
Note

The default for this class will be to write a script (R Core Team 2021).R file – and then copy and paste results into a Word or Google Doc. 🫤

Though there are a few extra steps, my preference is quarto (RStudio Team 2020).qmd, however. 🤩 You’ll see why in a second.

5.2 Script (.R) 🫤

  • A file denoted with the .R file extension
  • A file specifically designed to send code to an RStudio (RStudio Team 2020) console.
  • Only allows you to evaluate R (R Core Team 2021) code.
  • Have to take the results of your script and place them in a document for your reports/papers/etc.

5.3 Quarto (.qmd) 🤩

  • A file denoted with the .qmd file extension
  • A file that allows you to not only write R code and to evaluate it but it also:
    • lets you evaluate other coding languages too (e.g., python)
    • uses code chunks which evaluates the R code, but also lets you write text around the chunk.
  • This is useful if you want to write a paper or report that requires you to evaluate some type of code in it
    • You write your code and the other parts of your paper all in the same document 😮
    • You render the file and it evaluates the code in your chunks and spits out the result of the code in the document along with your text.
  • Allows you to compile documents of many different file types
    • documents
      • HTML
      • PDF
      • DOCX
    • slide decks (presentations)
      • PDF
      • PPT
      • a very pretty and interactive JavaScript
    • websites
    • books
      • HMTL
      • PDF
  • This site that you are reading right now was created with .qmd.
  • To set all of this up though, it requires slightly extra work… 🙀