+ - 0:00:00
Notes for current slide
Notes for next slide

Week 6: Scripts/Projects and Quarto

PUBPOL 750 Data Analysis for Public Policy I

Justin Savoie

MPP-DS McMaster

2023-10-24

1 / 11

Scripts and Projects

R4DS Chapter 7

2 / 11

Scripts

  • console is to run quick code (bottom left)
  • script is to work on longer chunks of code (top left)
  • anything you write in the script, you can save
  • anything you write in the console, you don't save
  • you send code to the console from the script by clicking run or by hitting Cmd/Ctrl + Enter. The code to run can be highlighted but it doesn't have to: it's it not highlighted it will run the current line/block
  • you should read section 7.1 for more details
3 / 11

Projects

  • your source of truth should be the R scripts
  • everything should be reproducible
  • you should start with data files and write R code (R code is what we call a script)
  • if you send the data and the script to me, I should be able to reproduce everything in one click

  • RStudio projects: keep all the files associated with a given project (input data, R scripts, analytical results, and figures) together in one directory

  • Inside a project, you only use relative path
  • Let's do an example in RStudio (you can also just read 7.2.3 and code along)
4 / 11

Quarto

An open-source scientific and technical publishing system

5 / 11

Quarto

  • for communicating to decision makers
  • for collaborating with other data scientists and analysts
  • as an environment in which to do data science
  • "Here's some data, could you run cross-tabs, run these six models, export all this in pdf format. I'd need this tomorrow / no need for clean formatting."
  • Quarto is also great for slide decks, books (R4DS) and more (dissertations, reports, etc.)
  • Very similar to R Markdown, which was what people used before Quarto
6 / 11

7 / 11

8 / 11

9 / 11

Code chunks

To run code inside an R Markdown document, type the chunk delimiters

```{r} and ``` .

We can also do everything in visual mode.

Chunk options

  • eval=FALSE prevents code from being evaluated
  • include = FALSE runs the code, but doesn’t show the code or results in the final document.
  • echo = FALSE prevents code, but not the results from appearing in the finished file.
  • message = FALSE or warning = FALSE prevents messages or warnings from appearing in the finished file
  • results = hide hides printed output
  • fig-show: hide hides plot

  • All the details and more in Chapter 29!

10 / 11

Example with 2021 Democracy Checkup

11 / 11

Scripts and Projects

R4DS Chapter 7

2 / 11
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow