Skip to content

Commit

Permalink
Moved quarto to week 9
Browse files Browse the repository at this point in the history
  • Loading branch information
robjhyndman committed Apr 24, 2024
1 parent 2b5d09b commit 15b77eb
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 110 deletions.
4 changes: 2 additions & 2 deletions course_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ schedule <- tibble(
"Functional programming",
"Object-oriented programming",
"Object-oriented S3 and vctrs",
"Literate and reactive programming",
"Targets: reproducible workflows",
"Reactive and literate programming",
"Quarto and targets: efficient reproducible workflows",
"Metaprogramming",
"Interfacing with other languages",
"Rewriting R code in C++"
Expand Down
4 changes: 1 addition & 3 deletions week8/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ source(here::here("course_info.R"))

## What you will learn this week

* [Shiny](https://shiny.rstudio.com)
* [roxygen2](https://r-pkgs.org/man.html)
* [Rmarkdown](https://bookdown.org/yihui/rmarkdown/)
* [Quarto](https://quarto.org)
* [Shiny](https://shiny.rstudio.com)

```{r}
#| output: asis
Expand All @@ -24,7 +23,6 @@ show_slides(week)

* [Rob's 2020 rstudio::conf talk on Rmarkdown](https://youtu.be/_D-ux3MqGug?si=LeXPIa9K3V9N1rO_)


```{r}
#| output: asis
show_assignments(week)
Expand Down
104 changes: 5 additions & 99 deletions week8/slides.qmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: ETC4500/ETC5450 Advanced&nbsp;R&nbsp;programming
author: "Week 8: Literate and reactive programming"
author: "Week 8: Reactive and literate programming"
format:
beamer:
pdf-engine: pdflatex
Expand Down Expand Up @@ -217,7 +217,7 @@ With declarative code you say “Ensure there is a sandwich in the refrigerator

\fontsize{13}{13}\sf
::: {.callout-important title="Use-less cases"}
This paradigm is rarely needed or used in R for data analysis.
This paradigm is rarely needed or used in R for data analysis.
:::

::: {.callout-tip title="Useful cases"}
Expand Down Expand Up @@ -290,11 +290,11 @@ Reactivity in shiny comprises of:

UI inputs `input*()` and values `reactiveValues()`

* Reactive **conductors** (intermediates):
* Reactive **conductors** (intermediates):

Expressions `reactive()` and events `eventReactive()`

* Reactive **endpoints** (results):
* Reactive **endpoints** (results):

UI outputs `render*()` and side-effects `observe()`

Expand Down Expand Up @@ -408,7 +408,7 @@ Other ways reactivity might be prevented include:

* `eventReactive(rnorm(input$n_samples), input$go)`
* `observeEvent(input$go, message("Go!"))`

* Rate limiting

* `throttle(reactive())`: limits update frequency
Expand Down Expand Up @@ -710,97 +710,3 @@ summarize
#| echo: true
names(knitr::knit_engines$get())
```

# Quarto

## Quarto
\fontsize{14}{16}\sf

* Generalization of Rmarkdown (not dependent on R)
* Supports R, Python, Javascript and Julia chunks by using either `knitr`, `jupyter` or `ObservableJS` engines.
* More consistent yaml header and chunk options.
* Many more output formats, and many more options for customizing format.
* Heavier reliance on pandoc Lua filters
* Uses pandoc templates for extensions

\centerline{\includegraphics[width = 10cm]{qmd.png}}

## Choose your engine

Specify the engine in the yaml header:

````{verbatim}
---
engine: knitr
---
````

````{verbatim}
---
engine: jupyter
jupyter: python3
---
````


**Default:** If any `{r}` blocks found, use `knitr` engine; otherwise use `jupyter` (with kernel determined by first block).


## Execute options

* `execute` option in yaml header can be used instead of a `setup` chunk:

````{verbatim}
execute:
cache: true
echo: false
warning: false
````
* `setup` chunk still allowed.
## Chunk options
Rmarkdown syntax recognized for R chunks.
More consistent chunk options use the hash-pipe `#|`
````{verbatim}
```{r}
#| label: fig-chunklabel
#| fig-caption: My figure
#| fig-width: 6
#| fig-height: 4
mtcars |>
ggplot(aes(x = mpg, y = wt)) +
geom_point()
```
````

## Chunk options

* Quarto consistently uses hyphenated options (`fig-width` rather than `fig.width`)
* The Rmarkdown `knitr` options are recognized for backwards compatibility.
* Options that are R expressions need to be prefaced by `!expr`

````{verbatim}
```{r}
#| fig-cap: !expr paste("My figure", 1+1)
```
````

## Extensions and templates
\fontsize{13}{17}\sf

* Quarto extensions modify and extend functionality.
* See <https://quarto.org/docs/extensions/> for a list.
* Templates are extensions used to define new output formats.
* Journal templates at\newline <https://quarto.org/docs/extensions/listing-journals.html>
* Monash templates at\newline <https://robjhyndman.com/hyndsight/quarto_templates.html>

## Exercise

* Create a quarto document using an html format
* Add a code chunk to generate a figure with a figure caption.
* Reference the figure in the text using `@fig-chunklabel`.
* Add the monash memo extension and generate a pdf output.
File renamed without changes.
21 changes: 15 additions & 6 deletions week9/index.qmd
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
---
title: "Week 9: targets"
title: "Week 9: Quarto and targets -- efficient reproducible workflows"
---

```{r}
week <- 9
source(here::here("course_info.R"))
```

## Main reference

[The {targets} R package user manual](https://books.ropensci.org/targets/)

## What you will learn this week

* Using the [targets package](https://docs.ropensci.org/targets/) for efficient and reproducible data analysis
* [Quarto](https://quarto.org)
* [The {targets} R package user manual](https://books.ropensci.org/targets/)


```{r}
#| output: asis
show_slides(week)
```

## Other resources

* [Quarto extensions](https://quarto.org/docs/extensions/)
* [Monash quarto templates](https://robjhyndman.com/hyndsight/quarto_templates.html)
* [targets package](https://docs.ropensci.org/targets/)


```{r}
#| output: asis
show_assignments(week)
```
File renamed without changes
136 changes: 136 additions & 0 deletions week9/slides.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
title: ETC4500/ETC5450 Advanced&nbsp;R&nbsp;programming
author: "Week 8: Quarto and targets -- efficient reproducible workflows"
format:
beamer:
pdf-engine: pdflatex
aspectratio: 169
fontsize: "14pt,t"
section-titles: false
knitr:
opts_chunk:
dev: "cairo_pdf"
fig-width: 7.5
fig-height: 3.5
include-in-header: ../header.tex
colorlinks: true
urlcolor: MonashBlue
linkcolor: burntorange
---

```{r}
#| label: setup
#| include: false
#| cache: false
source(here::here("setup.R"))
source(here::here("course_info.R"))
```

## Outline

\vspace*{0.4cm}
\tableofcontents

# Assignments

## Assignments 3 and 4

* Assignment 3 due 10 May
* Assignment 4 due 24 May


# Quarto

## Quarto
\fontsize{14}{16}\sf

* Generalization of Rmarkdown (not dependent on R)
* Supports R, Python, Javascript and Julia chunks by using either `knitr`, `jupyter` or `ObservableJS` engines.
* More consistent yaml header and chunk options.
* Many more output formats, and many more options for customizing format.
* Heavier reliance on pandoc Lua filters
* Uses pandoc templates for extensions

\centerline{\includegraphics[width = 10cm]{qmd.png}}

## Choose your engine

Specify the engine in the yaml header:

````{verbatim}
---
engine: knitr
---
````

````{verbatim}
---
engine: jupyter
jupyter: python3
---
````


**Default:** If any `{r}` blocks found, use `knitr` engine; otherwise use `jupyter` (with kernel determined by first block).


## Execute options

* `execute` option in yaml header can be used instead of a `setup` chunk:

````{verbatim}
execute:
cache: true
echo: false
warning: false
````
* `setup` chunk still allowed.
## Chunk options
Rmarkdown syntax recognized for R chunks.
More consistent chunk options use the hash-pipe `#|`
````{verbatim}
```{r}
#| label: fig-chunklabel
#| fig-caption: My figure
#| fig-width: 6
#| fig-height: 4
mtcars |>
ggplot(aes(x = mpg, y = wt)) +
geom_point()
```
````

## Chunk options

* Quarto consistently uses hyphenated options (`fig-width` rather than `fig.width`)
* The Rmarkdown `knitr` options are recognized for backwards compatibility.
* Options that are R expressions need to be prefaced by `!expr`

````{verbatim}
```{r}
#| fig-cap: !expr paste("My figure", 1+1)
```
````

## Extensions and templates
\fontsize{13}{17}\sf

* Quarto extensions modify and extend functionality.
* See <https://quarto.org/docs/extensions/> for a list.
* Templates are extensions used to define new output formats.
* Journal templates at\newline <https://quarto.org/docs/extensions/listing-journals.html>
* Monash templates at\newline <https://robjhyndman.com/hyndsight/quarto_templates.html>

## Exercise

* Create a quarto document using an html format
* Add a code chunk to generate a figure with a figure caption.
* Reference the figure in the text using `@fig-chunklabel`.
* Add the monash memo extension and generate a pdf output.

# targets

0 comments on commit 15b77eb

Please sign in to comment.