Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure path in Readme gets relocated #1943

Closed
mrcaseb opened this issue Dec 3, 2021 · 3 comments
Closed

Figure path in Readme gets relocated #1943

mrcaseb opened this issue Dec 3, 2021 · 3 comments

Comments

@mrcaseb
Copy link
Contributor

mrcaseb commented Dec 3, 2021

It seems like this test is testing that figure paths to man/figures are relocated to reference/figures which breaks any figure in the Readme that links to man/figures

test_that("links to man/figures are automatically relocated", {
# weird path differences that I don't have the energy to dig into
skip_if(identical(R.version$crt, "ucrt"))
pkg <- local_pkgdown_site(test_path("assets/man-figures"))
expect_output(copy_figures(pkg))
expect_output(build_articles(pkg, lazy = FALSE))
html <- xml2::read_html(path(pkg$dst_path, "articles", "kitten.html"))
src <- xpath_attr(html, "//img", "src")
expect_equal(src, c(
"../reference/figures/kitten.jpg",
"../reference/figures/kitten.jpg",
"another-kitten.jpg",
"https://www.tidyverse.org/rstudio-logo.svg"
))
# And files aren't copied
expect_false(dir_exists(path(pkg$dst_path, "man")))
})

I don't know how to provide a reprex for this so I link to the Readme.md of my pkgdown site and the corresponding html.
The readme links to man/figures
https://github.com/nflverse/nflfastR/blob/e5928b49622469d183d19d6a9dbc7399bf163f30/README.md?plain=1#L106
while the actual html links to reference/figures
https://github.com/nflverse/nflfastR/blob/c2fd9e9c3a2cd987a5f973cefca551c9773731d7/index.html#L190

@hadley
Copy link
Member

hadley commented Dec 3, 2021

Yes, that's where figures go; there's no man directory on the website (just in the package).

Instead of:

```{r echo=FALSE, fig.align='center', fig.cap='', out.width='100%'}
knitr::include_graphics('https://github.com/nflverse/nflfastR/raw/master/man/figures/readme-epa-model-1.png')
```

You need

```{r echo=FALSE, fig.align='center', fig.cap='', out.width='100%'}
knitr::include_graphics('man/figures/readme-epa-model-1.png')
```

That will work locally, and will be automatically relocated on your site.

@hadley hadley closed this as completed Dec 3, 2021
@wkdavis
Copy link

wkdavis commented Dec 3, 2021

If you look at this example here: https://github.com/wkdavis/rpkgreprex/runs/4408853389?check_suite_focus=true, at the very end of the "Create Website" step you can see this warning message:

Warning message:
Missing images in 'README.md': 'reference/figures/README-pressure-1.png'
ℹ pkgdown can only use images in 'man/figures' and 'vignettes' 

I'm not sure what the purpose of this warning message is, because the image is in man/figures, and the website seems to build correctly.

@mrcaseb
Copy link
Contributor Author

mrcaseb commented Dec 3, 2021

Yes, that's where figures go; there's no man directory on the website (just in the package).

Instead of:

```{r echo=FALSE, fig.align='center', fig.cap='', out.width='100%'}
knitr::include_graphics('https://github.com/nflverse/nflfastR/raw/master/man/figures/readme-epa-model-1.png')

You need

knitr::include_graphics('man/figures/readme-epa-model-1.png')

That will work locally, and will be automatically relocated on your site.

Sorry, my bad. This worked fine. Thanks for the reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants