Search code examples
r-markdownrstudiopandocquarto

Do Quarto publish on quarto-pub (book format) images from web links?


I want to publish with the command

quarto::quarto_publish_site()

my book-website.

The book-website is already setup on quarto-pub. If I don't add any image as a web link, the website runs and can be uploaded.

Now I add any image as a weblink, this is a exemplary code

![](https://www.website.com/wp-content/uploads/sites/2/2022/04/picture.jpg)

When I render it locally, it works. When I launch the command to publish it

compilation failed- error Unable to load picture or PDF file 'https://www.website.com/wp-content/uploads/sites/2/2022/04/picture.jpg'.

The publishing process is interrupted after this error. This is exactly the same if I launch the command from Terminal.

Is this intended to prevent to publish on quarto-pub links from other websites? Or I can do something to avoid to download all these pics?


Solution

  • Including images via URL is not supposed to work for PDF output, which is not a Quarto issue but comes from how Pandoc translates !()[] to LaTeX.

    Instead, you could automatically generate a local copy of the file (if not available) and then include the image in an R code chunk like this:

    ```{r, echo=FALSE, fig.cap='Kid', dpi=100}
    if(!file.exists("kid.jpg")) {
      download.file(
        url = "https://edit.co.uk/uploads/2016/12/Image-1-Alternatives-to-stock-photography-Thinkstock.jpg",
        destfile = "kid.jpg", 
        mode = "auto") 
      }
    knitr::include_graphics("kid.jpg")
    ```
    

    (of course, including the image via !()["kid.jpg"] at different location will work too once the file exists locally.)