2023 DSS Bootcamp
2022-08-25
Markdown is a lightweight markup language for creating HTML (and other formatted) documents.
Markup languages are designed to produce documents from human readable text (and annotations).
Some of you may be familiar with LaTeX. This is another (less human friendly) markup language for creating pdf documents.
Why markdown is great:
R Markdown:
---
title: "Untitled"
output: html_document
date: "2023-08-22"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Quarto:
---
title: "Untitled"
format: html
---
## 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:
```{r}
1 + 1
```
You can add options to executable code like this
```{r}
#| echo: false
2 * 2
```
The `echo: false` option disables the printing of code (only output is displayed).
Something simple
Something fancy
In RStudio, go to Help > Cheatsheets
and select
Check out the official R Markdown book: R Markdown: The Definitive Guide by Yihui Xie, J. J. Allaire, and Garrett Grolemund
Check out bookdown: Authoring Books and Technical Documents with R Markdown by Yihui Xie.
Take a look at RPubs web published R Markdown documents.
Much of the syntax is shared with R Markdown - so previous resources are a good place to start
Tom Mock’s Intro to Quarto webinar
RStudioConf 2023 workshops
Packages are the fundamental units of reproducible R code. They include reusable R functions, the documentation that describes how to use them, and sample data.
In the following exercises we’ll use the tidyverse
package.
ggplot2
, tibble
, tidyr
, readr
, purrr
, dplyr
, stringr
, and forcats
packages.This package is already installed for you on the DSS servers. If needed, you can install it by running the following in the Console
:
Your R Markdown / Quarto document and your Console do not share their global environments.
This is good for reproducibility, but can sometimes result in frustrating errors.
This also means any packages or data needed for your analysis need to be loaded in your R Markdown document as well.
To get started,
open examples/unvotes.qmd
,
try Rendering the entire document and examine the results.
try changing one or more of the selected countries, re-render the document and observe any changes.
commit and push your changes to GitHub (include the newly generated unvotes.html
file as well)
Remember to name your code chunks
Familiarize yourself with chunk options (https://yihui.org/knitr/options/)
#|
syntax enables tab completion for chunk optionsLoad packages at the start of a document, generally the chunk after your setup chunk
Familiarize yourself with various output formats: Make slides with revealjs
, pdfs, books, etc.
Style
Beginner
Next steps
Some useful resources from RStudio: https://www.rstudio.com/resources/cheatsheets/
Some of the above cheat sheets are available in RStudio: Help > Cheatsheets
To see how technologies have trended over time based on use of their tags since 2008 we can look at Stack Overflow trends.
If you return to https://rstudio.stat.duke.edu you can launch a new session and select Jupyter Lab as your editor of choice.
Bimodal interface: edit mode and command mode
Click in a cell or hit enter
to enter edit mode
When in edit mode you can type code or write text with markdown.
Hit esc
to enter command mode
When in command mode you can make edits to the notebook, but not individual cells.
In edit mode:
shift + enter
- Run cell and add new cellenter
- Add a line within a cellIn command mode:
s
- Save the notebookm
- Change cell to markdowny
- Change cell to codex
, c
, v
, d
- Cut, copy, paste, delete a cella
, b
- Add a cell above, belowThe point-and-click interface is also an option to execute these commands.
Jupyter Lab provides a direct interface to the terminal (similar to RStudio) under Launcher > Other
Terminal commands can also be included in notebooks by prefixing with !
, e.g.
The departmental server has the git jupyter lab extension installed.
This provides a GUI similar to RStudio’s for interacting with Git repositories
Navigate to a repo’s root directory and then switch to the Git pane.
To get started,
open examples/unvotes.ipynb
,
Render the entire document by selecting Run > Run All Cells
Try changing one or more of the selected countries, rerunning the document, observe any changes.
commit and push your changes to GitHub (include the newly generated unvotes.html
file as well)
Similar to R Markdown, Jupyter notebooks allow you to write code and text in one easy to read document that is reproducible and easy to share with others.
Jupyter notebooks include the text, code and computational output.
A Jupyter notebook does not knit to an HTML, PDF or Word file. However, you can embed HTML into a notebook.
nbcovert
For a more detailed comparison see The First Notebook War.
Quarto was build to unify the scientific publish process across the most commonly used notebook formats and this include Jupyter notebooks.
Specifically, quarto has a couple of neat tricks:
Render ipynb
files using the jupyter engine
quarto render unvotes.ipynb --execute
quarto render unvotes.ipynb --execute --to pdf
Converts between ipynb
and qmd
files seamlessly
quarto convert unvotes.ipynb
Style
Beginner
Next steps