Eden
Eden

Reputation: 458

How to insert external images in a vignette knit using pkgdown in R

I am trying to use pkgdown to knit vignettes and have them posted on GitHub, along with the rest of a package's documentation, using GitHub Actions. I can also knit the pages locally. Regardless, external images I want in the vignette are not showing--the "broken image" icon appears instead whether I knit them locally or through GH Actions.

I would love to post a minimally reproducible example, but I have not been able to make a minimal package that can do that. I will instead post a link to the package in the comments because if I can get this fixed, it will no longer be an example of the issue I'm trying to fix.

I'm using pkgdown 2.1.1 on R 4.4.0. I am inserting the images using:

![](man/figures/elev_rivers.png)

Here is what I have tried.

  1. Putting images in man/figures. I get this error in R when using pkgdown::build_articles(): enter image description here

(I'll deal with the accessibility issue later.) However, I have the correct figures in man/figures:

enter image description here

Notice that these are PNG files, so I'm avoiding the issue raised here.

  1. Editing the vignette's YAML.

According to the pkgdown manual, I may need to insert pointers to the files in the vignette's YAML:

enter image description here (image from the manual--and why is it showing an example of an image in an images folder?)

But I have:

enter image description here

  1. Putting image files in the vignettes folder.

According to the Writing R Extensions Manual, "All other files needed to re-make the vignettes (such as LaTeX style files, BibTeX input files and files for any figures not created by running the code in the vignette) must be in the vignette source directory."

I have tried that, too:

enter image description here What am I missing?

In case anyone asks, I'm not generating the images during the build process because to make them, GRASS GIS has to be installed. When GH Actions builds the web pages, it would fail because GRASS is not installed on the GH Actions system.

Upvotes: 0

Views: 88

Answers (1)

Eden
Eden

Reputation: 458

So, here are the solutions to get external images to display in vignettes.

External images in vignettes
To get local, external images to display in vignettes, despite all instruction to the contrary like here and here, I needed to:

a) Save images to ./vignettes/images; then
b) Refer to them in the vignette's .Rmd file using links like . The "." at the start is important.

External images in vignettes in pkgdown site built using GitHub Actions
The pkgdown site is built in a repo named gh-pages. Switch your branch to that one, and create a subfolder in the articles folder named reference, and inside of that, create subfolder named figures. Copy your figures to there, and it should work.

I have found no documentation of the need to do this, and indeed, would have expected usethis::use_pkgdown_github_pages() to have set this up to automatically happen.

Upvotes: 0

Related Questions