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 @@ - + @@ -37,12 +37,12 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + @@ -36,12 +37,12 @@ - - + + - - + + + + - - + + - - + + -
+

Cross-references, bibliography and citations in Quarto files

@@ -330,6 +379,7 @@

Cross-references, bibliography and citations in Quarto filesInsert citations and a bibliography into a Quarto document
  • Customize citation and bibliography styles
  • Add cross-referencing for tables, figures, and sections to direct your readers through your document
  • +
  • Make dynamic captions for tables and figures
  • @@ -340,7 +390,302 @@

    Today’s Car
    1. https://carpentries-incubator.github.io/reproducible-publications-quarto/02-quarto/08-biblio-crossref/index.html
    -

    For this week’s tutorials, we will be relying on the forked repository from previous sessions. If you have not yet set up your forked repository in RStudio, follow the instructions here: https://nmfs-opensci.github.io/Quarto-Workshop-2024/tutorials/tutorial-2.html#instructions-for-forking-the-carpentries-example-repository

    +

    We will again be relying on the forked repository from previous sessions. If you have not yet set up your forked repository in RStudio, follow the instructions here: https://nmfs-opensci.github.io/Quarto-Workshop-2024/tutorials/tutorial-2.html#instructions-for-forking-the-carpentries-example-repository

    + +
    +

    Creating Dynamic Captions

    +

    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.

    +
    +
    # Create a dummy dataset
    +dat <- data.frame(species = rep('Mycteroperca microlepis', 10),
    +                  gear = rep(c('HL','LL','SP','UA'),5),
    +                  age = 1:20,
    +                  size = seq(1,100,5))
    +
    +write.csv(dat, file = 'dat_colval.csv',row.names = F)
    +
    +

    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). +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    speciesgearagesizegear_name
    Mycteroperca microlepisHL11hook and line
    Mycteroperca microlepisLL26longline
    Mycteroperca microlepisSP311spear
    Mycteroperca microlepisUA416unassigned gear code
    Mycteroperca microlepisHL521hook and line
    Mycteroperca microlepisLL626longline
    Mycteroperca microlepisSP731spear
    Mycteroperca microlepisUA836unassigned gear code
    Mycteroperca microlepisHL941hook and line
    Mycteroperca microlepisLL1046longline
    Mycteroperca microlepisSP1151spear
    Mycteroperca microlepisUA1256unassigned gear code
    Mycteroperca microlepisHL1361hook and line
    Mycteroperca microlepisLL1466longline
    Mycteroperca microlepisSP1571spear
    Mycteroperca microlepisUA1676unassigned gear code
    Mycteroperca microlepisHL1781hook and line
    Mycteroperca microlepisLL1886longline
    Mycteroperca microlepisSP1991spear
    Mycteroperca microlepisUA2096unassigned 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.

    +
    +
    # Create a dummy dataset
    +dat <- data.frame(species = rep('Mycteroperca microlepis', 10),
    +                  SL = 1:10,
    +                  FL = 1:10)
    +
    +write.csv(dat, file = 'dat_colname.csv',row.names = F)
    +
    +
    +
    # 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))
    +
    +
    +
    +
    + +
    +
    +Figure 1: Mycteroperca microlepis SL vs. 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 @@

    Connect Zotero } }); +