From R Markdown to Quarto
rstudio::conf 2022
Andrew Bray
To get the materials for each part of this course packed in an RStudio Project, run:
You can also
git clone
if you prefer that workflow.
From the last exercise . . .
This looks familiar!
From the last exercise . . .
This looks familiar!
. . . but this does not.
Highlight content for the reader in multiple formats.
Highlight content for the reader in multiple formats.
Highlight content for the reader in multiple formats.
Quarto makes available several layout attributes that apply to broad range of block elements.
layout-ncol
: split elements across n columns (2
, 3
, …).layout-nrow
: split elements across n rows (2
, 3
, …).layout-valign
: align elements (top
, center
, bottom
, default
).layout
: Split elements into a 2D array by rows and columns1.layout-ncol
:::{layout-ncol=2}
A novelty clock, watch, and the like for
keeping time at an animal's rate, defined
in terms of a multiple of human rate by
dividing the average lifetime of a
particular animal into the average
lifetime of a human being. The multiple
for dogs is seven, for example.
![](images/dog-watch.png)
:::
A clock for keeping time at an animal’s rate. The multiple for dogs is seven, for example.
layout-ncol
+ layout-valign
:::{layout-ncol=2 layout-valign=middle}
A novelty clock, watch, and the like for
keeping time at an animal's rate, defined
in terms of a multiple of human rate by
dividing the average lifetime of a
particular animal into the average
lifetime of a human being. The multiple
for dogs is seven, for example.
![](images/dog-watch.png)
:::
A clock for keeping time at an animal’s rate. The multiple for dogs is seven, for example.
layout-ncol
with small image
:::{layout-ncol=2}
A novelty clock, watch, and the like for
keeping time at an animal's rate, defined
in terms of a multiple of human rate by
dividing the average lifetime of a
particular animal into the average
lifetime of a human being. The multiple
for dogs is seven, for example.
![](images/dog-watch-small.png)
:::
A clock for keeping time at an animal’s rate. The multiple for dogs is seven, for example.
layout
: The layout attribute1 is a 2-dimensional array where the first dimension defines rows and the second columns.
layout="[[1,1], [1]]"
translates to: create two rows, the first of which has two columns of equal size and the second of which has a single column.1
s.What would layout="[[1,5], [1]]"
do?
Modify the width of the main body column for individual block elements (e.g. paragraph, figures).
:::{.column-body}
A novelty clock, watch, and the like for
keeping time at an animal's rate, defined
in terms of a multiple of human rate by
dividing the average lifetime of a
particular animal into the average
lifetime of a human being. The multiple
for dogs is seven, for example.
:::
:::{.column-screen}
A novelty clock, watch, and the like for
keeping time at an animal's rate, defined
in terms of a multiple of human rate by
dividing the average lifetime of a
particular animal into the average
lifetime of a human being. The multiple
for dogs is seven, for example.
:::
Modify the width of the main body column for individual block elements (e.g. paragraph, figures).
:::{.column-body}
A novelty clock, watch, and the like for
keeping time at an animal's rate, defined
in terms of a multiple of human rate by
dividing the average lifetime of a
particular animal into the average
lifetime of a human being. The multiple
for dogs is seven, for example.
:::
:::{.column-screen}
A novelty clock, watch, and the like for
keeping time at an animal's rate, defined
in terms of a multiple of human rate by
dividing the average lifetime of a
particular animal into the average
lifetime of a human being. The multiple
for dogs is seven, for example.
:::
Place any inline or block element from the body to the margin.
Place any inline or block element from the body to the margin.
What is your preferred method of adding a figure to an Rmd so that it displays in HTML at 300 pixels wide?
A. markdown
B. html
C: knitr
Quarto expands the functionality of markdown. Set width
, height
, fig-align
, add link, caption, and alt-text.
px
.300in
, 300%
(relative to image size), 3em
(relative to font size).[fig](url)
) to link the imageIn additional to external resources, links can go to elements of the same doc through its #id
.
< Much more text >
A novelty clock, watch, and the like for keeping time at an animal’s rate . . .
References can be made dynamic using #<type>-id
and @<type>-id
.
< Much more text >
A novelty clock, watch (Figure 1), and the like for keeping time at an animal’s rate . . .
<type>
include @tbl-
,@sec-
, @eq-
, @thm-
, and manyYou can customize the appearance of inline references by either changing the syntax of the inline reference or by setting options.
Type | Syntax | Output |
---|---|---|
Default | @fig-elephant |
Figure 1 |
Custom Prefix | [Fig @fig-elephant] |
Fig 1 |
No Prefix | [-@fig-elephant] |
1 |
Let’s play around in the RStudio Visual Editor!
Have the editor write the markdown for you!
Type /
on a new line to search the element types.
Click ...
next to elements to see the attributes you can change.
Ctrl + space
to see all available options then tab-complete. Also works in VSCode.
Open ex-3.qmd
and follow the directions to create a document that describes your favorite place to visit on vacation.
When you’re done, please share a screenshot of your document in the GitHub Discussion thread “Exercise 3”.
I’ll show you three webpages briefly.
What do you think they’re for?
Who do you think is their audience?
I’ll show you three webpages briefly.
What do you think they’re for?
Who do you think is their audience?
A document consists of content, structure, appearance, format.
A demonstration of what can be accomplished through CSS-based design. Select any style sheet from the list to load it into this page.
A collection of CSS rules that define font, colors, and spacing is called a theme. Quarto has 25 pre-loaded themes from Bootswatch.
{fig-alt=“screenshot of a collection of bootswatch themes.}
Add a Bootswatch theme to your ex-3.qmd
by adding the following to your YAML.
You can find the list of theme names at Quarto Guide >> Documents >> HTML.
Try out several of the themes (or view them at https://bootswatch.com/) then apply your favorite and share a screenshot of the styled document in the GitHub Discussion thread “Exercise 3”.
HTML, like markdown, has a set of elements that structure a website: <div>
, <body>
, <pre>
, <span>
, etc. Compare:
A Span Element.
we can add labels.
. . . still looks the same. Let’s add some style.
A Span Element.
There are many many many CSS properties available for styling.
https://www.w3schools.com/cssref/
Take a moment and add a few more different style properties from the list to a test span in your sandbox.
Syntax: style="property-1: value; property-2: value"
If you have a style that you want to apply multiple times, it makes sense to encapsulate it in a CSS rule. Why?
If you have a [style]{style="font-size: 1.5em; text-decoration: underline"} that you want to apply [multiple times]{style="font-size: 1.5em; text-decoration: underline"}, it makes sense to encapsulate it in a CSS rule. Why?
Don’t Repeat Yourself (DRY): repetitive code is hard to update… and long!
To write a rule for a class.
To write a rule for a class.
If you have a [style]{.loud} that you want to apply [multiple times]{.loud}, it makes sense to encapsulate it in a CSS rule. Why?
There are three CSS challenges in this exercise
On your way out the door for lunch, please write on the blue sticky note one that confused or frustrated you and on the yellow sticky something that you enjoyed, or got your excited.