Welcome to Posit Cloud!

Author

Your Name Here!

Published

April 7, 2023

Quarto

This is a Quarto document!

Quarto is a software that allows you to interweave text and R code to create HTML, PDF, and Microsoft Word documents

There are two ways to view a Quarto document, (1) as the “Source” file, or (2) as the “Visual” file. We will only use the Visual option in this class, as it allows you to interact with Quarto similar to how you interact with Word.

Formatting your Document

Similar to a Word Doc, there are a variety of ways you can spice up a Quarto document! Let’s explore a few.

Question 1: Using the formatting options, make a numbered list of your top three favorite animals.

Question 2: Using the formatting options, insert an image of your favorite animal.

Question 3: Now, change the “Formatting your Document” section name to the name of your favorite animal. Make sure your header is a level 1 – use the Header 1 formatting option!

R Code

You can differentiate the R code within a Quarto file from the body of the document, based on the gray boxes that start with an {r}.

Here is an example of an R code chunk:

Notice that after the {r} there is a name (packages), that is the name of the code chunk. It is good practice to name your code chunks based on the action they perform. It makes it easier to navigate to them in the navigation pane.

This code chunk has three things we want to pay attention to:

  1. The #| include: false option at the beginning of the code chunk. We use these options to control how the code output looks in our final rendered document.

  2. The library(tidyverse) code loads in an R package called the “tidyverse”. This is code you will have in every lab assignment for this class!

  3. Code comments which are denoted by a ## symbol. Code comments are a way for you (and me) to write what the code is doing, without R thinking what we are writing is code it should execute.

Rendering

When you click the Render button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

Question 4: Do you see the above code chunk when you knit the document? Why do you think this is the case?

Including Code Output

You can include code output in your knitted document:

glimpse(mpg)
Rows: 234
Columns: 11
$ manufacturer <chr> "audi", "audi", "audi", "audi", "audi", "audi", "audi", "…
$ model        <chr> "a4", "a4", "a4", "a4", "a4", "a4", "a4", "a4 quattro", "…
$ displ        <dbl> 1.8, 1.8, 2.0, 2.0, 2.8, 2.8, 3.1, 1.8, 1.8, 2.0, 2.0, 2.…
$ year         <int> 1999, 1999, 2008, 2008, 1999, 1999, 2008, 1999, 1999, 200…
$ cyl          <int> 4, 4, 4, 4, 6, 6, 6, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, …
$ trans        <chr> "auto(l5)", "manual(m5)", "manual(m6)", "auto(av)", "auto…
$ drv          <chr> "f", "f", "f", "f", "f", "f", "f", "4", "4", "4", "4", "4…
$ cty          <int> 18, 21, 20, 21, 16, 18, 18, 18, 16, 20, 19, 15, 17, 17, 1…
$ hwy          <int> 29, 29, 31, 30, 26, 26, 27, 26, 25, 28, 27, 25, 25, 25, 2…
$ fl           <chr> "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p…
$ class        <chr> "compact", "compact", "compact", "compact", "compact", "c…

Question 5: What do you think the above code does? What type of output does it give you?
Hint: You have saw this type of output earlier today!

Including Plots

You can also embed plots in the rendered document.

Here is an example of a plot.

Question 6: What do you think the echo: false option does in the above code chunk?

Question 7: What do you think the mapping = aes(y = manufacturer, x = hwy)) code does?

Question 8: What do you think the labs(x = "Highway Miles Per Gallon", y = "Car Manufacturer") code does?