使用 knitr::include_graphics 将图像从 url 插入到 Rmakdown

Inserting images from url to Rmakdown using the knitr::include_graphics

我正在尝试将图像从 pandoc 复制到 Rmarkdown

pandoc 方式:

 ![](https://images.unsplash.com/photo-1563204996-8965f0a4a860?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80)

我的试用版 Rmarkdown:

url <- "https://images.unsplash.com/photo-1563204996-8965f0a4a860?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80"

knitr::include_graphics(url, dpi = 600)

我能够编织文件并生成与 pandoc 相同的图像,但还想将图形的输出 width 设置为 600px我正在尝试将其放入 dpi=600.

我怀疑执行此操作后图像是否实际调整了大小,或者是否有其他方法?

对我来说,knitr::include_graphics()dpi 参数也不会更改 HTML 或 DOCX 输出的图像大小。设置块选项 out.width 的作用是什么?您可以使用像素值(见下文)或百分比(例如“25%”)。

```{r out.width="300px"}
url <- "https://images.unsplash.com/photo-1563204996-8965f0a4a860?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80"
knitr::include_graphics(url)

```

有关详细信息,请参阅 R-Markdown Cookbook 的第 5.4 章。