Quarto Introduction

Your Name

Learning Objectives

  1. Open the quarto introduction file in your Rstudio and render to create an html output file
  2. Learn some basic markdown syntax to include text and run code
  3. Alter the YAML to include your name and output to a different file format (e.g. docx)

R packages used

For this introduction, I used three R packages. If you have never used these before, they will need to be installed once, e.g.

install.packages("ggplot2")
install.packages("rms")
install.packages("Hmisc")

If they have already been installed, you can load these packages.

library(ggplot2)
library(rms)
Loading required package: Hmisc

Attaching package: 'Hmisc'
The following objects are masked from 'package:base':

    format.pval, units
library(Hmisc)

Quarto

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

Quarto includes many more features than I will cover in this course. It is not a learning objective of this course that you learn all of the features included in Quarto. Instead, I want to cover a few of the most useful things and provide a starting point for those interested in learning more.

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

You can add options to executable code like this

[1] 4

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

Plots

You can include plots

ggplot(cars, aes(x=speed, y=dist)) + 
  geom_smooth() + 
  xlab("Speed (mph)") + 
  ylab("Stopping Distance (feet)")
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Date recorded in the 1920s

Speed and stopping distance of cars

Tables

And tables that are simple text

# Create some data
set.seed(12345) # Fpr reproducibility
exampledata <- data.frame(age=rnorm(500,50,5),
                          sbp=rnorm(500,120,12),
                          trt=factor(sample(c("Drug","Placebo"), 500, replace=TRUE))
)
f <- summaryM(age + sbp ~ trt, data=exampledata, test=TRUE)
print(f, digits=2)


Descriptive Statistics  (N=500)

+---+------------------+------------------+------------------------+
|   |Drug              |Placebo           |  Test                  |
|   |(N=260)           |(N=240)           |Statistic               |
+---+------------------+------------------+------------------------+
|age|        47/50/53  |        47/51/54  | F=0.5 d.f.=1,498 P=0.48|
+---+------------------+------------------+------------------------+
|sbp|       113/120/129|       112/120/128|F=0.02 d.f.=1,498 P=0.89|
+---+------------------+------------------+------------------------+

Table can also be formatted to improve appearance. Here is an html version of the same table.

html(f, digits=3)
Descriptive Statistics (N=500).
Drug
N=260
Placebo
N=240
Test Statistic
age 47.4 50.3 53.2 47.0 50.7 54.0 F1 498=0.5, P=0.479
sbp 113 120 129 112 120 128 F1 498=0.02, P=0.89
a b c represent the lower quartile a, the median b, and the upper quartile c for continuous variables.
Test used: Wilcoxon test .

Quarto YAML

The beginning of this document of the document contains metadata that controls the document appearance, output format, and many other options. The current lines were automatically generated when I create a new document (File > New File > Quarto Document…)

For longer documents, it can be useful to add a table of contents. A simple toc can added with the line.

toc: true

Also, the default output type is an html document. This is a good choice, but if you prefer other options, you can alter the yaml to produce Word files, PDFs, or many other options. Tab-completion is supported to see the various options.

In order to create PDFs you will need to install a recent distribution of TeX. We recommend the use of TinyTeX (which is based on TexLive), which you can install with the following command:

quarto install tinytex

More details on authoring Quarto documents in Rstudio are available elsewhere.

Thing to try

  1. Alter the YAML to include your name
  2. Alter the YAML to output to a different file format, e.g. docx
  3. Add some text, code, or graphics and render the document