Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have `pkgdown` use figure numbers and cross-references in vignettes?

I've created several vignettes for a package, with figures I want to reference in the text. Using the template for a .Rmd vignette, I can do this by using bookdown::html_document2 as follows in my yaml header:

output: 
  bookdown::html_document2:
    base_format: rmarkdown::html_vignette
    fig_caption: yes
    toc: true

Yet, when I build the associated pkgdown site, I don't get figure numbers or cross-references, done with \@ref(fig:chunk_name).

Is there some magic I can add to my _pkgdown.yml file to have it use the bookdown output format?

Edit: Not sure if this has anything to do with this issue, but my figure chunk labels are of the form topic-figure rather than topic_figure. E.g.,

```{r, plastic1-HE3D}
#| echo=FALSE,
#| fig.cap="3D HE plot for the plastic MLM"
knitr::include_graphics("fig/plastic-HE3D.png")
```
like image 576
user101089 Avatar asked Oct 17 '25 03:10

user101089


1 Answers

A solution that seems to work is suggested in https://github.com/r-lib/pkgdown/issues/2201

Essentially, add pkgdown: as_is: true to the yaml headers of vitnettes:

output: 
  bookdown::html_document2:
    base_format: rmarkdown::html_vignette
    fig_caption: yes
    toc: true
    toc_depth: 2
pkgdown:
  as_is: true
like image 185
user101089 Avatar answered Oct 19 '25 16:10

user101089