forked from laderast/qmd_rmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.qmd
519 lines (390 loc) · 10 KB
/
index.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
---
title: "Quarto/RMarkdown - What's Different?"
author: Ted Laderas
subtitle: Hymans Robertson R User Group
date: 1/18/2023
format:
revealjs:
standalone: true
theme: night
progress: true
footer: <https://laderast.github.io/qmd_rmd/>
incremental: false
highlight-style: a11y
---
## Agenda for Today
- What is Quarto?
- Should you switch from RMarkdown?
- Demo
- Guide to Converting RMarkdown
- Questions
## About Me
:::: {.columns}
::: {.column width="65%"}
- Bioinformatics Trainer at [DNAnexus](https://dnanexus.com)
- [Posit Academy](https://www.posit.co/academy) Data Science Mentor
- RStudio/Carpentries Certified Instructor
- Twitter: @tladeras
- Web: <https://laderast.github.io/>
:::
::: {.column width="35%"}
![](ted.jpg)
:::
::::
# What is Quarto?
## What is Quarto?
- **Reproducible Publishing** System based on Pandoc
- One format, many outputs
- Website
- Publications
- Books
- **Dashboards**
## .qmd files
- Short for **q**uarto **m**ark**d**own
- Decoupled from RStudio IDE
- plugins for VSCode, JupyterLab and RStudio are available
- Can still Render within RStudio
- Render with quarto standalone on command line:
```{.bash}
quarto render my_document.qmd
```
## Cross Language Support
- Supports a number of languages:
- R
- Python
- Julia
- Observable
- Can [interchange between languages using Apache Arrow](https://gist.github.com/hrbrmstr/23355194d1964688596553a0e6a0050a)
## Jupyter Notebook Support
- [Jupyter Notebooks are cross compatible](https://quarto.org/docs/tools/jupyter-lab.html)
- One command to interchange:
```{.bash}
quarto convert notebook.ipynb
```
Fast way to publish Jupyter Notebooks!
## Code Output Freezing
- By default, code is not recomputed
- `quarto render --execute` will recompute
- Output is "frozen"
```{.markdown}
execute:
freeze: auto # re-render only when source changes
```
## Code Chunks
Options are moved to within the code chunk using `#|` (hash-pipe) for each line
## RMarkdown {auto-animate="true"}
````{.markdown}
```{{r setup, include=FALSE}}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(DT)
library(ggimage)
```
````
## Quarto {auto-animate="true"}
````{.markdown}
```{{r}}
#| label: "setup"
#| include: false
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(DT)
library(ggimage)
```
````
# What's Different with Quarto?
## How is Quarto different from RMarkdown?
- Standardized YAML across formats
- Decoupled from RStudio
- More consistent presentation across formats
- Tab Panels
- Code Highlighting
## Should I Switch to Quarto?
> Should you switch to Quarto? Not necessarily.
> If you find R Markdown meet your need, you can definitely stay there. It is not imperative to switch. - Yihui Xie
::: aside
<https://yihui.org/en/2022/04/quarto-r-markdown/>
:::
## Some Killer Apps for Quarto (HTML)
- Output Freezing
- Precise Layouts
- Tab Panels
- Code Highlighting
## Freeze Results and avoid recomputing
- Creates a `_freeze/` directory in your project
- Saves intermediate output
```{bash}
#| eval: false
#| echo: true
#| filename: _quarto.yml
project:
title: "qmd_rmd"
type: website
output-dir: docs
freeze: true
```
## Freeze Results: CLI
- Results are frozen with `quarto render` by default.
- Use `--execute` to recompute:
```{bash}
#| echo: true
#| eval: false
quarto render . --execute
```
## Layout Example
````{.markdown}
:::: {.columns}
::: {.column width="50%"}
- Highly customizable
- Less work than using `<div>` tags
:::
::: {.column width="50%"}
- Customizable in terms of layouts
:::
::::
````
## Layout Example
:::: {.columns}
::: {.column width="50%"}
- Highly customizable
- Less work than using `<div>` tags
:::
::: {.column width="50%"}
- Customizable in terms of layouts
:::
::::
## Tabsets
````{.markdown}
::: {.panel-tabset}
### Code
This is where I would put some code:
### Figure
ggpplot code here
:::
````
## Tabsets
::: {.panel-tabset}
### Code
This is where I would put some code:
````{.markdown}
```{{r}}
library(palmerpenguins)
library(ggplot2)
data(penguins)
ggplot(penguins, aes(x=bill_depth_mm, y=bill_length_mm, color = species)) + geom_point()
```
````
### Figure
```{r}
library(palmerpenguins)
library(ggplot2)
data(penguins)
ggplot(penguins, aes(x=bill_depth_mm, y=bill_length_mm, color = species)) + geom_point()
```
:::
## Code Highlighting
- Incremental highlighting (line by line)
- Killer app for me
- Really good for teaching!
````{.markdown}
```{{r}}
#| echo: TRUE
#| eval: FALSE
#| code-line-numbers: "3|4-6|7"
library(palmerpenguins)
library(ggplot2)
data(penguins)
ggplot(penguins) + aes(x=bill_depth_mm,
y=bill_length_mm,
color = species) +
geom_point()
```
````
## Code Highlighting Example
```{r}
#| echo: TRUE
#| eval: FALSE
#| code-line-numbers: "3|4-6|7"
library(palmerpenguins)
library(ggplot2)
data(penguins)
ggplot(penguins) + aes(x=bill_depth_mm,
y=bill_length_mm,
color = species) +
geom_point()
```
# How to move to Quarto
## Checklist
1. Start a Quarto Project
1. For your documents: Change your `output:` to the corresponding `format:` in your YAML
1. Use `knitr::convert_chunk_header()` to convert your code blocks (outputs a `.qmd` file)
1. Render your files
1. For websites: edit your `_quarto.yml` file if necessary
## 1. Start a Quarto Project
:::: {.columns}
::: {.column width="50%"}
**File >**
**New Project >**
**New Directory >**
**Quarto Project**
:::
::: {.column width="50%"}
![Quarto Project Start](quarto_project.png)
:::
::::
## 2. Convert your Rmarkdown Documents
- Change your YAML header
- Instead of `output: `, use `format: `
## {auto-animate="true"}
````{.markdown}
---
title: "Quarto/RMarkdown - What's Different?"
author: Ted Laderas
subtitle: FCT Abuja useR Group
date: 9/15/2022
output:
xaringan::moon_reader:
lib_dir: libs
css: xaringan-themer.css
---
````
## {auto-animate="true"}
````{.markdown}
---
title: "Quarto/RMarkdown - What's Different?"
author: Ted Laderas
subtitle: FCT Abuja useR Group
date: 9/15/2022
format:
revealjs:
self-contained: true
theme: night
footer: <https://laderast.github.io/qmd_rmd/>
incremental: false
highlight-style: github
---
````
## 2. RMarkdown/Quarto Formats
| RMarkdown | Quarto |
|:-----------|:-------|
| `output: html_document` | [`format: html`](https://quarto.org/docs/output-formats/html-basics.html)|
| `output: pdf_document` | [`format: pdf`](https://quarto.org/docs/output-formats/pdf-basics.html) |
| `output: word_document` | [`format: docx`](https://quarto.org/docs/output-formats/ms-word.html) |
| `output: xaringan` | [`format: revealjs`](https://quarto.org/docs/presentations/revealjs/) |
| `output: ioslides` | [`format: revealjs`](https://quarto.org/docs/presentations/revealjs/) |
| `output: distill` | [Quarto Article Layout](https://quarto.org/docs/authoring/article-layout.html)
::: aside
<https://quarto.org/docs/faq/rmarkdown.html>
:::
## 3. Convert your RMarkdown Code Chunks
`knitr::convert_chunk_header()` will convert your RMarkdown code chunks into quarto compatible format.
```{{r}}
knitr::convert_chunk_header("filename.Rmd",
output = "filename.qmd")
```
## 3. Converting Code Chunks
::: {.panel-tabset}
### Original Chunk
````{.markdown}
```{{r setup, include=FALSE}}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(DT)
library(ggimage)
```
````
### Converted Chunk
````{.markdown}
```{{r}}
#| label: "setup",
#| include: FALSE
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(DT)
library(ggimage)
```
````
:::
## 4. Render via RStudio GUI
- Render button in RStudio
```r
quarto::quarto_render()`
```
## 4. Render via Command Line
```{.bash}
> quarto render <filename>
```
## 5. Update your `_quarto.yml` for websites
- Controls [navigation and visibility of documents](https://quarto.org/docs/websites/)
```{markdown}
#| echo: TRUE
#| eval: FALSE
#| filename: _quarto.yml
#| code-line-numbers: "1-2|4-6|7-13"
project:
type: website
website:
title: "Ted Laderas, PhD"
description: "Ted's R and Teaching Blog"
navbar:
right:
- teaching.qmd
- articles.rmd
- blog.qmd
- talks.qmd
- notebook.ipynb #works for Jupyter notebooks!
```
## Mix and Match Formats
```{markdown}
#| echo: TRUE
#| eval: FALSE
#| code-line-numbers: "7|8|10"
#| filename: _quarto.yml
website:
title: "Ted Laderas, PhD"
description: "Ted's R and Teaching Blog"
navbar:
right:
- teaching.qmd
- articles.rmd
- blog.qmd
- talks.qmd
- notebook.ipynb
```
## Publish your files (on CLI)
`quarto publish` can push and update a number of different kinds of webhosts.
You will need credentials to publish to each of these.
```{.bash}
quarto publish gh-pages # GitHub Pages
quarto publish quarto-pub # Quarto.pub
quarto publish netlify # Netlify
quarto publish connect # RStudio Connect
```
::: aside
<https://quarto.org/docs/publishing/>
:::
## Multiple languages
Hand off data objects with multiple languages in a Quarto Document
|Languages|Method|
|---------|-----|
|Python <=> R | `{reticulate}`/Apache Arrow or Pandas|
|R <=> JavaScript |`ojs_define()` function|
|Python <=> JavaScript | `ojs_define` function|
## Apache Arrow
- "Language Independent Columnar memory format"
- Handles very large datasets / CSV files
- Code example here [Intro to Apache Arrow](https://github.com/laderast/intro_to_arrow)
## Observable/Shiny
- Use Observable Components (`viewof`, Observable Plot) with Shiny
- `viewof` inputs are passed into Shiny's `input` opject
- Use `ojs_define()` function to pass reactives to Observable code chunks
- [Example/Demo](https://github.com/laderast/ojs_shiny_example)
## Conclusions
- Quarto supports multiple languages / IDEs
- Quarto standardizes a lot of outputs
- Does a better job of one document, many outputs
- Lots of publishing features (references, figures, etc.)
## Learn More
- Workshop materials from Andrew Bray: <https://github.com/rstudio-conf-2022/rmd-to-quarto>
- Repository for this talk: <https://github.com/laderast/qmd_rmd>
# Thank You! Questions?