Doing some more investigating. It appears that external images are not supported by LaTeX by default, but there are workarounds.
Something strange is going on though. I can create the PDF using knitr::knit() followed by rmarkdown::pandoc_convert(), which is the general strategy used by rmarkdown::render(). The output test.pdf contains the image, just as expected.
Here's a reprex to demonstrate the issue:
rmd <- tempfile(fileext = ".Rmd")
md <- tempfile(fileext = ".md")
pdf <- tempfile(fileext = ".pdf")
writeLines(c(
"```{r ext-fig}",
"knitr::include_graphics(\"https://imgur.com/Kt5CR1H.jpg\")",
"```"),
con = rmd)
# This works
knitr::knit(rmd, output = md)
rmarkdown::pandoc_convert(md, to = "latex",
output = pdf,
verbose = TRUE)
# This fails
rmarkdown::render(rmd, rmarkdown::pdf_document())
When I run it in Ubuntu, I see the following:
Click to display results
> rmd <- tempfile(fileext = ".Rmd")
> md <- tempfile(fileext = ".md")
> pdf <- tempfile(fileext = ".pdf")
> writeLines(c(
+ "```{r ext-fig}",
+ "knitr::include_graphics(\"https://imgur.com/Kt5CR1H.jpg\")",
+ "```"),
+ con = rmd)
> # This works
> knitr::knit(rmd, output = md)
processing file: /tmp/Rtmptr2FWv/file19c84de330be.Rmd
|.................................................................| 100%
label: ext-fig
output file: /tmp/Rtmptr2FWv/file19c84d78fb80.md
[1] "/tmp/Rtmptr2FWv/file19c84d78fb80.md"
> rmarkdown::pandoc_convert(md, to = "latex",
+ output = pdf,
+ verbose = TRUE)
/usr/lib/rstudio-server/bin/pandoc/pandoc +RTS -K512m -RTS /tmp/Rtmptr2FWv/file19c84d78fb80.md --to latex --output /tmp/Rtmptr2FWv/file19c83c964008.pdf
> # This fails
> rmarkdown::render(rmd, rmarkdown::pdf_document())
processing file: file19c84de330be.Rmd
|.................................................................| 100%
label: ext-fig
output file: file19c84de330be.knit.md
/usr/lib/rstudio-server/bin/pandoc/pandoc +RTS -K512m -RTS file19c84de330be.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output file19c84de330be.tex --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --lua-filter /usr/lib/R/site-library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /usr/lib/R/site-library/rmarkdown/rmd/lua/latex-div.lua --variable 'geometry:margin=1in'
! Package pdftex.def Error: File `https://imgur.com/Kt5CR1H.jpg' not found: usi
ng draft setting.
Error: LaTeX failed to compile file19c84de330be.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See file19c84de330be.log for more info.
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.3 magrittr_1.5 htmltools_0.4.0 tools_3.6.3
[5] tinytex_0.21 Rcpp_1.0.4.6 rmarkdown_2.1 stringi_1.4.6
[9] highr_0.8 knitr_1.28 digest_0.6.25 stringr_1.4.0
[13] xfun_0.13 rlang_0.4.5 evaluate_0.14
(Note: I tried using reprex, but it failed for a different reason, so I didn't want to complicate the example further)