Codefrag in a deck

Annotations, one arrow press at a time

Stepping through annotations

Press the arrow keys: each annotation is revealed in turn, with its tooltip.

library(dplyr)
starwars |>
  filter(species == "Droid") |>
  select(name, height, mass)
1
Load the package.
2
Start from the dataset.
3
Keep the droids.
4
Keep three columns.

Highlights that match the annotations

Each highlight covers one line, and each annotation marks the same line. One press moves the highlight and opens the note together.

library(dplyr)
starwars |>
  filter(species == "Droid")
1
Load the package.
2
Start from the dataset.
3
Keep the droids.

An annotation inside a highlighted range

The first highlight covers lines one and two, and the first note marks line two alone. The note still pairs with that highlight, because its line sits inside the range.

library(dplyr)
starwars |>
  filter(species == "Droid")
1
Inside the first highlight.
2
The third line.

A note that is open before the first press

There is no leading | below, so line one is highlighted as soon as the slide opens. The note on line one opens with it and takes no step of its own.

library(dplyr)
starwars |>
  filter(species == "Droid")
1
Open before the first press.
2
Start from the dataset.
3
Keep the droids.

A note that matches no highlight

Two highlights cover lines one and two, and the third note marks line three. That note pairs with nothing, so it gets a step after the highlights.

library(dplyr)
starwars |>
  filter(species == "Droid")
1
Load the package.
2
Start from the dataset.
3
Last, with the highlight left on line two.

Choosing when each annotation appears

code-annotation-fragment-indices interleaves the annotations with the other fragments on the slide.

First, a package.

Then the data.

Then the filter.

library(dplyr)
starwars |>
  filter(species == "Droid")
1
Load the package.
2
Start from the dataset.
3
Keep the droids.

Choosing when each highlight appears

code-line-fragment-indices does the same for the highlight steps. The paragraph below was given index one, and the two highlights were given two and four, so the paragraph arrives first.

Set up the two panels.

par(mfrow = c(1, 2))
plot(cars)
plot(cars, col = "red")

Annotations in a column layout

A column clips nothing, so each tooltip stays where Quarto put it.

starwars |>
  head(3)
1
Start from the dataset.
2
Take the first three rows.

The plugin moves a tooltip up to the slide only when something between the marker and the slide clips its overflow.

Why it helps

Without the plugin, the annotations are all present at once and the audience reads ahead.