pkgdown icon indicating copy to clipboard operation
pkgdown copied to clipboard

False warning for missing (articles) images in README.md

Open maelle opened this issue 3 years ago • 2 comments

For a README.Rmd with

knitr::include_graphics("vignettes/data_sources.png")

a first run of build_site() leads to

Warning message:
Missing images in 'README.md': 'articles/data_sources.png'
ℹ pkgdown can only use images in 'man/figures' and 'vignettes' 

The image is then present. It is very close to #1980 so should the fix be an extension of https://github.com/r-lib/pkgdown/commit/8b2f4d0a500c911255ce51b19ff193582b4e67bb to vignettes/ images?

cc @mcguinlu

maelle avatar Sep 12 '22 09:09 maelle

Reprex https://github.com/maelle/readme.images

maelle avatar Sep 12 '22 10:09 maelle

I also want to report that I have observed different behavior for pkgdown::build_site() when I change only the location of the folder that contains my package.

When I am developing my package, the location of the folder with all my code is:

~/Dropbox/path with spaces/some long path/mypackage

When I run build_site():

  • I get the weird warnings about missing images (there are none, I checked each and every one).
  • The warning message contains an incorrect path that does not exist, and this path contains ../../../../... (To me, this indicates that there must be a bug in the code that tries to guess the parent folder of an image.)
  • One image — that is not missing — fails to appear in the vignette's html, and I inspected the <img> element to find out that it contains that erroneous ../../../../../.. path.

So, I decided to check what happens when I run this instead:

cp -r "~/Dropbox/path with spaces/some long path/mypackage" /tmp/
cd /tmp/mypackage
# now run pkgdown::build_site()

Now the result is different:

  • I still get the weird warnings about missing images.
  • The paths falsely reported as missing no longer contain ../../../../...
  • The image successfully appears in the vignette's html!

I hope this report helps you to gain more insight into the problem. Good luck!

If I have more time to debug this in the future, I'll try to share what I have learned.

slowkow avatar Jun 24 '23 21:06 slowkow

Hmmmm, the problem is that build_home_index() is called before build_articles(), so the images are missing at the time the check is done. And we can't just replicate copy_figures() because there are no images to even copy yet.

So I think the best option is likely to move check_missing_images() to build_site_local() after both readme and articles have been built. Might be worth wrapping this in a new check_site() function where in the future we can add other code that can only be run after all pages are generated.

hadley avatar Apr 16 '24 13:04 hadley