Skip to content
R for the Rest of Us Logo

Tips for Working with Quarto


Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Your Turn

  1. Working in your report.qmd file, right below the YAML, add a code chunk that loads the tidyverse and imports your penguins data to an object called penguins.

  2. Add a first-level heading with the text Results.

  3. Right below the Results heading, create a second code chunk and add some code that you used to make a graph in the data viz section of the course.

  4. Render your document and make sure it works!

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Brian Slattery

Brian Slattery

October 4, 2023

For the third tip, I wasn't sure if there was a way to source R script documents in a Quarto document? I tried googling this and it looked like there was a source() function that lets R script files reference other R script files, but it seemed like there were some limitations too. I wasn't sure how Quarto documents differed from R script documents in that way. Thanks!

Gracielle Higino

Gracielle Higino

October 4, 2023

Hey, Brian! For this tip you don't need to source - copy+paste is enough! - but you can do that for sure! It's a great thing to learn. I'm not aware of the limitations of sourcing, it has always worked fine for me, but I know you need to write your R script in a way that is independent (i.e., it must be able to run alone or it has a very clear chain of execution with other scripts). For rendering Quarto documents, you should add local = knitr::knit_global() as an argument of your source() function. For example, if I want to source an R script that creates an object that stores a plot called p, I could add this to my code chunk:

source("my_beautiful_plot.R", local = knitr::knit_global())    #sources the code that creates the object
p    # displays the object

Quarto is a way to render Pandoc Markdown markup language, which means it is a way to control structure, format and relationships in a document. R scripts are a "roadmap" of functions to execute that will only result in more data or plots. When we add a code chunk in a *.qmd file, we are adding a relationship between an R script and other elements of the document.

I hope that's helpful!