12.1 Bookdown Insert Image From URL
20210316
With multiple output targets, such as html and latex, we need a little care in ensuring each is supported. A common use case is to include an image from a specific URL with the html document. This is accomplished with markdown:
![](https://bit.ly/3lfNVG6)
However for latex output the path is expected to be a local path to the image file. Instead we can utilise knitr::include_url():
if (knitr::is_html_output())
{
knitr::include_graphics("https://bit.ly/3lfNVG6")
} else {
knitr::include_url("https://bit.ly/3lfNVG6")
}
This might be included in an R code block that begins with:
{r echo=FALSE, fig.align="left", out.width="50%"}
An image can be resized:
![](graphics/mypic.png]{width=40%}
Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0