Reputation: 505
I am trying to include a picture file from the internet in my R Markdown report. I am hoping to print this out on to a pdf file. However, whenever I try to run my code, I get a LaTeX file not found error. The picture exists on the web, I just can't seem to be able to bring it into my report.
My code:
```{r, out.width = "50%"}
include_graphics("https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/MC_Drei-Finger-Faultier.jpg/330px-MC_Drei-Finger-Faultier.jpg")
```
My error is this: ! LaTeX Error: File `https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/ MC_Drei-Finger-Faultier.jpg/330px-MC_Drei-Finger-Faultier' not found.
The picture in question: https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/MC_Drei-Finger-Faultier.jpg/330px-MC_Drei-Finger-Faultier.jpg
I am using:
Upvotes: 2
Views: 372
Reputation: 4243
To display an image from a URL in a pdf, you have to first download the file. You may need a different mode
depending on your OS.
```{r, out.width = "50%"}
myurl <- "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/MC_Drei-Finger-Faultier.jpg/330px-MC_Drei-Finger-Faultier.jpg"
download.file(url = myurl, destfile = 'temp.jpg', mode = 'wb')
knitr::include_graphics('temp.jpg')
Upvotes: 2