If you are knitting to PDF, the file has to run through LaTeX. LaTeX has no built-in capacity to display files hosted on the web, as highlighted in this question.
The best workaround for this is to download the web image to your local directory, and then specify this as a file path.
The following code downloads the image using the download.file function, and then displays in using include_graphics
. The benefit of include graphics is that it allows you to specify the width of the image in the output document, which I set to 40 pixels.
---
title: "Random"
output: pdf_document
---
```{r results = 'asis', out.width="40px"}
download.file(url = "https://octodex.github.com/images/bannekat.png",
destfile = "image.png",
mode = 'wb')
knitr::include_graphics(path = "image.png")
```
Find out more reasons why include_graphics
should be used to include graphics in R Markdown documents. Check out my other answer here for more details why.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…