Creating a Lab Group Handbook with Quarto

Eric R. Scott

2024-08-28

Learning Objectives

  • Understand the purpose of and benefits of a lab group handbook

  • Gain a basic understanding of what Quarto can do

  • Get set up using GitHub if you aren’t already

  • Create a repository from a template on GitHub

  • Edit Quarto markdown documents and YAML configurations to customize your group’s handbook

Lab Handbook

From Tendler et al. (2023):

  • Communicates lab ethos

  • Normalizes and communicates expectations

  • Improves equity among lab members

  • Streamlines and standardizes onboarding and offboarding

Lab Handbook

Quarto

  • “An open-source scientific and technical publishing system”

  • The successor to RMarkdown (but don’t worry if you’ve never used RMarkdown!)

  • Combines prose, code, and code output into a variety of output formats

GitHub

  • A platform for sharing files (often code)

  • Enables collaboration via git, a version-control tool

  • Automated deployment of rendered Quarto book to the web

  • Controlled way of merging edits and contributions to your book

Do I really have time for this?

Get Set Up with GitHub

Hello GitHub, can you hear me?

Goal: get RStudio set up to work with git and GitHub

  • In RStudio: tools > Global Options > Git/SVN

  • Check that “Git executable:” isn’t blank

  • If it is, you may need to find/install git

  • Run usethis::git_sitrep() and follow steps

GitHub organizations

  • A central place for all the lab’s projects

  • Allow you to manage team members access

  • When a member leaves your lab, their code stays in the lab organization

Tip

Learn more about GitHub organizations and how to create one: https://docs.github.com/en/organizations

Create a GitHub organization (optional)

  • Click the “+” button in the upper right and choose “New Organization”

  • Choose a plan (the free plan is likely all you need)

  • Follow the prompts to create your organization

Create your handbook

  • Go to our template on GitHub and click the “Use Template” button

  • (Optional) choose your newly-created GitHub organization under “Owner”

  • Give your repo a name, e.g. “scott-lab-handbook”

Open your handbook in RStudio

Next you need to clone your repository locally, so you can work on it on your computer

  • In your repo on GitHub, click the green “< > Code” button, copy the url

  • In RStudio, new project > from version control > paste url

  • Edit the README, commit, push, and check GitHub

Quarto

Preview your book!

Run quarto preview in the terminal to see a live preview of your lab handbook!

Your book features

  • Search bar
  • Dark mode switch
  • Table of contents for book (left) and within pages (right)
  • Links to view and edit source code and report issues on GitHub (these are not “hooked up” yet—we will fix this together)

Take a Break

10:00

Anatomy of a .qmd

myreport.qmd
---
title: "My Report"
author: "Eric Scott"
format: 
  html:
    toc: true
---

```{r}
#| label: load-packages
#| include: false

library(tidyverse)
library(gapminder)
```

## Data

My data source is the [gapminder](https://www.gapminder.org/) dataset.

```{r}
head(gapminder)
```

Markdown Basics

Markdown is a “markup language” that let’s you write plain text to indicate formatting. For example:

  • **bold text** becomes bold text

  • ~~strikethrough~~ becomes strikethrough

  • $E = mc^2$ becomes \(E = mc^2\)

  • [link](https://www.google.com) becomes link

  • `code()` becomes code()

Check Help > Markdown quick reference in RStudio

Visual Editor

  • Makes editing Quarto documents a lot like editing a Word doc

  • Explore creating sections, lists, tables, images, callouts, and references

  • Open the “add anything” menu with

  • Save changes, practice commit & push

Shortcodes

Note

You don’t need to use shortcodes, but there are some already in the template.

  • Shortcodes look like {{< something something >}} and get replaced on render with something (text, icons, videos, etc. depending on the shortcode)

  • For an example, see contributing.qmd

  • Some shortcodes are built-in (like the meta shortcode) and some are from extensions (like the fa shortcode)

_quarto.yml

  • YAML works with nested key: value pairs.

  • Nesting is indicated with indentation

  • Use _quarto.yml to configure your book including adding new chapters and controlling chapter order.

Tip

Indentation is a common source of frustration with YAML—the wrong number of spaces can completely break things.

Add a new chapter

  • Create a new .qmd file

  • Give it a title with a level 1 header (# Title)

  • Add that chapter to _quarto.yml

  • (Optionally) link to it in other chapters with [link text](filename.qmd)

Complete (?) list of edits

In README.md

  • Edit to be about your book
  • Include links to template, your lab website, etc.

In _quarto.yml

  • book: title:
  • book: repo-url
  • book: author:
  • book: date:
  • Possibly re-order or add new chapters:

In code-of-conduct.qmd

  • Replace GROUP_NAME, PI_NAME, and PI_EMAIL
  • Double-check links to UA policies

In content (all .qmd files)

  • Edit and add content!
  • Remove all .callout-important boxes—these are just prompts to give ideas for content

Publish your (WIP) book

In the terminal…

  • Stop the quarto preview process
  • Run quarto render
  • Run quarto publish gh-pages
  • When successful, it should open up in your web browser!

Automatic Publishing

  • After manually publishing this first time, you should (🤞) be able to just push changes to GitHub and it will automatically re-publish your book!

  • This happens because of a GitHub action included in .github/

  • Try another round of edit, save, commit, push and then check the “Actions” tab of your GitHub repository.

Resources

References

Braga, Pedro Henrique Pereira, Katherine Hébert, Emma J. Hudgins, Eric R. Scott, Brandon P. M. Edwards, Luna L. Sánchez Reyes, Matthew J. Grainger, et al. 2023. “Not Just for Programmers: How GitHub Can Accelerate Collaborative and Reproducible Research in Ecology and Evolution.” Methods in Ecology and Evolution 14 (6): 1364–80. https://doi.org/https://doi.org/10.1111/2041-210X.14108.
Tendler, Benjamin C, Maddie Welland, Karla L Miller, and The WIN Handbook Team. 2023. “Why Every Lab Needs a Handbook.” eLife 12 (July): e88853. https://doi.org/10.7554/eLife.88853.