diff --git a/.nojekyll b/.nojekyll
index 3b7aa65..dbbca80 100644
--- a/.nojekyll
+++ b/.nojekyll
@@ -1 +1 @@
-109de0bb
\ No newline at end of file
+3acea858
\ No newline at end of file
diff --git a/coc.html b/coc.html
index 780cd4e..fd79a7b 100644
--- a/coc.html
+++ b/coc.html
@@ -2,7 +2,7 @@
We can create captions for tables and figures that are dynamic based on our code. We will be going through a quick example of how this can be done using knitr. Below are a couple examples that were produced for one of the Quarto teams. Feel free to play around with this with your own variables and datasets.
+
+
+
Example 1: from a column value
+
If the information for our dynamic caption is contained within a column in the dataset (say, a single static column for the species or gear), we can extract the information from the columns of interest. Let’s create a dataset with a constant species and gear.
We can make a dynamic label in a few ways. If a caption with a similar format is going to be used multiple times throughout the document, it might be easiest to make this a function. Otherwise, we can just use a standard call to paste (note that paste0 is a special case of paste in which the separator argument is by default '' (no separator).
+
+
# Make dynamic label
+# read in the data file
+library(tidyverse)
+
+
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
+✔ dplyr 1.1.4 ✔ readr 2.1.5
+✔ forcats 1.0.0 ✔ stringr 1.5.1
+✔ ggplot2 3.5.1 ✔ tibble 3.2.1
+✔ lubridate 1.9.3 ✔ tidyr 1.3.1
+✔ purrr 1.0.2
+── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
+✖ dplyr::filter() masks stats::filter()
+✖ dplyr::lag() masks stats::lag()
+ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
+
+
dat <-read.csv('dat_colval.csv') %>%
+mutate(gear =factor(gear),
+gear_name =factor(case_when(gear =='HL'~'hook and line',
+ gear =='LL'~'longline',
+ gear =='SP'~'spear',
+ gear =='UA'~'unassigned gear code')))
+
+
+# extract the species name
+spp <-unique(dat$species)
+
+# extract the gear
+gear <-levels(dat$gear)
+
+# extract the gear name
+gear_name <-levels(dat$gear_name)
+
+# paste the gear name and its abbreviation together with the abbreviation inside parentheses
+gear_caption_string <-paste0(gear_name,' (',gear,')')
+
+# paste together the caption
+cap <-paste0('Age and length of ',
+ spp,
+' from ',
+paste(gear_caption_string[-length(gear_caption_string)],collapse =', '),
+', and ',
+ gear_caption_string[length(gear_caption_string)],
+'.')
+cap
+
+
[1] "Age and length of Mycteroperca microlepis from hook and line (HL), longline (LL), spear (SP), and unassigned gear code (UA)."
+
+
+
We can assign the caption using the #| tbl-cap option in our table code chunk. To input an r variable, we use the following notation:
+
#| tbl-cap: !expr cap
+
By using !expr we can insert an R variable or even a full expression into the caption. This example inserts the value of the R variable cap into the caption.
+
+
# Make table using kable
+library(knitr)
+kable(dat)
+
+
+
+Table 1: Age and length of Mycteroperca microlepis from hook and line (HL), longline (LL), spear (SP), and unassigned gear code (UA).
+
+
+
+
+
+
+
species
+
gear
+
age
+
size
+
gear_name
+
+
+
+
+
Mycteroperca microlepis
+
HL
+
1
+
1
+
hook and line
+
+
+
Mycteroperca microlepis
+
LL
+
2
+
6
+
longline
+
+
+
Mycteroperca microlepis
+
SP
+
3
+
11
+
spear
+
+
+
Mycteroperca microlepis
+
UA
+
4
+
16
+
unassigned gear code
+
+
+
Mycteroperca microlepis
+
HL
+
5
+
21
+
hook and line
+
+
+
Mycteroperca microlepis
+
LL
+
6
+
26
+
longline
+
+
+
Mycteroperca microlepis
+
SP
+
7
+
31
+
spear
+
+
+
Mycteroperca microlepis
+
UA
+
8
+
36
+
unassigned gear code
+
+
+
Mycteroperca microlepis
+
HL
+
9
+
41
+
hook and line
+
+
+
Mycteroperca microlepis
+
LL
+
10
+
46
+
longline
+
+
+
Mycteroperca microlepis
+
SP
+
11
+
51
+
spear
+
+
+
Mycteroperca microlepis
+
UA
+
12
+
56
+
unassigned gear code
+
+
+
Mycteroperca microlepis
+
HL
+
13
+
61
+
hook and line
+
+
+
Mycteroperca microlepis
+
LL
+
14
+
66
+
longline
+
+
+
Mycteroperca microlepis
+
SP
+
15
+
71
+
spear
+
+
+
Mycteroperca microlepis
+
UA
+
16
+
76
+
unassigned gear code
+
+
+
Mycteroperca microlepis
+
HL
+
17
+
81
+
hook and line
+
+
+
Mycteroperca microlepis
+
LL
+
18
+
86
+
longline
+
+
+
Mycteroperca microlepis
+
SP
+
19
+
91
+
spear
+
+
+
Mycteroperca microlepis
+
UA
+
20
+
96
+
unassigned gear code
+
+
+
+
+
+
+
+
+
+
+
Example 2: from a column header
+
If instead our dynamic information is in a column header, we can use the colnames function to extract the appropriate information. This may be useful if the structure of the data is constant but a value column changes names across datasets. The below example is a bit trivial, but may be useful for certain cases.
# Make dynamic label
+# read in the data file
+dat <-read.csv('dat_colname.csv')
+
+# extract the species name
+spp <-unique(dat$species)
+
+# extract the length types
+param_1 <-colnames(dat)[2]
+
+param_2 <-colnames(dat)[3]
+
+# paste together the caption
+cap <-paste(spp,
+ param_1,
+'vs.',
+ param_2
+ )
+cap
+
+
[1] "Mycteroperca microlepis SL vs. FL"
+
+
+
+
# Make plot using ggplot
+library(ggplot2)
+ggplot(dat) +geom_point(aes(x = SL, y = FL))
+
+
+
+
+
+
+
+
+
Zotero and Quarto: a Powerful Pairing
@@ -597,8 +942,6 @@
Connect Zotero
});
clipboard.on('success', onCopySuccess);
if (window.document.getElementById('quarto-embedded-source-code-modal')) {
- // For code content inside modals, clipBoardJS needs to be initialized with a container option
- // TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860)
const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
text: getTextToCopy,
container: window.document.getElementById('quarto-embedded-source-code-modal')
@@ -709,7 +1052,6 @@
Connect Zotero
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
- // TODO in 1.5, we should make sure this works without a callout special case
if (note.classList.contains("callout")) {
return note.outerHTML;
} else {
@@ -935,6 +1277,18 @@