Quarto Demo

Author

Rosie

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
[1] 2
5+7
[1] 12
summary(cars)
     speed           dist       
 Min.   : 4.0   Min.   :  2.00  
 1st Qu.:12.0   1st Qu.: 26.00  
 Median :15.0   Median : 36.00  
 Mean   :15.4   Mean   : 42.98  
 3rd Qu.:19.0   3rd Qu.: 56.00  
 Max.   :25.0   Max.   :120.00  
hist(cars$speed)

Code chunk options

Your Quarto is broken up into ‘code’ chunks and text or ‘markdown’ chunks. Making nice looking Quarto documents means understanding how to format your code chunks and markdown chunks appropriately.

https://yihui.org/knitr/options/

You can add options to executable code like this

[1] 4

The echo: false option disables the printing of code (only output is displayed).

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
load("Dayflow.RData")

ggplot(Dayflow, aes(x = Date, y = SAC)) + geom_line()

Formatting Markdown chunks

A few hints for the markdown chunks:

  • You need two carriage returns to start a new line.
  • Asterisks or dashes make bullets
  • Hash tag indicate headings
  • You can use html for fancy formatting
  • css sheets are used for very fancy formatting (not covered here)
  • Use backticks to put code in text blocks function(x)

Quarto is an easy-to-write plain text format for creating dynamic documents and reports. See quarto.org to learn more.

Figures

You can include figures in a text chunk

image: Alt text

Or you can include them in code chunks.

#|fig.height=4
#|fig.align="center"
#|fig.cap="Alt text here"
#|echo=FALSE

knitr::include_graphics("figures/cheezburger-image.jpg")

By default, tables just print like they do in the consul when you knit the document

test = data.frame(Year = c(2000:2023), X =c(0:23), Y = c("Apple", "banana", "cheese"),
                  Z = c(exp(1), pi, exp(2)))

print(test)
   Year  X      Y        Z
1  2000  0  Apple 2.718282
2  2001  1 banana 3.141593
3  2002  2 cheese 7.389056
4  2003  3  Apple 2.718282
5  2004  4 banana 3.141593
6  2005  5 cheese 7.389056
7  2006  6  Apple 2.718282
8  2007  7 banana 3.141593
9  2008  8 cheese 7.389056
10 2009  9  Apple 2.718282
11 2010 10 banana 3.141593
12 2011 11 cheese 7.389056
13 2012 12  Apple 2.718282
14 2013 13 banana 3.141593
15 2014 14 cheese 7.389056
16 2015 15  Apple 2.718282
17 2016 16 banana 3.141593
18 2017 17 cheese 7.389056
19 2018 18  Apple 2.718282
20 2019 19 banana 3.141593
21 2020 20 cheese 7.389056
22 2021 21  Apple 2.718282
23 2022 22 banana 3.141593
24 2023 23 cheese 7.389056

You can do better with the kable function in the knitr package

#|results = 'asis'
library(knitr)
kable(test, format = "pipe", caption = "A prettier table", digits =2, padding =2)
A prettier table
Year X Y Z
2000 0 Apple 2.72
2001 1 banana 3.14
2002 2 cheese 7.39
2003 3 Apple 2.72
2004 4 banana 3.14
2005 5 cheese 7.39
2006 6 Apple 2.72
2007 7 banana 3.14
2008 8 cheese 7.39
2009 9 Apple 2.72
2010 10 banana 3.14
2011 11 cheese 7.39
2012 12 Apple 2.72
2013 13 banana 3.14
2014 14 cheese 7.39
2015 15 Apple 2.72
2016 16 banana 3.14
2017 17 cheese 7.39
2018 18 Apple 2.72
2019 19 banana 3.14
2020 20 cheese 7.39
2021 21 Apple 2.72
2022 22 banana 3.14
2023 23 cheese 7.39

You can make interactive and sortable tables with the DT package. https://rstudio.github.io/DT/

library(DT)

datatable(test, filter = "top", class = "cell-border stripe")

Further Reading

There are lots and lots of extensions you can add to your markdown documetns to make them really, really spiffy. A few examples: