我对即将推出的 RStudio 笔记本感到非常兴奋(可在 preview version of RStudio 中找到。有关简短概述,请单击 here)。但是,我遇到了一些 包含图像的困难 .
在 Rmarkdown 中,我可以包含这样的图像:
---
title: "This works"
output: html_document
---
```{r echo=FALSE, out.width='10%'}
library(knitr)
knitr::include_graphics('https://www.rstudio.com/wp-content/uploads/2014/06/RStudio-Ball.png')
```
但是,当我想在笔记本中做同样的事情时(注意从
html_document
到 html_notebook
的变化),我不再得到图像:---
title: "This does not work"
output: html_notebook
---
```{r echo=FALSE, out.width='10%'}
knitr::include_graphics('https://www.rstudio.com/wp-content/uploads/2014/06/RStudio-Ball.png')
```
(当我使用与笔记本相同文件夹中的图像时,我只需获取该图像的名称,就像指向外部图像的链接一样)。
我的问题:有没有办法在 rmarkdown 代码块内的笔记本(更新:)中显示图像?
请注意 :我想使用 r-code 来包含图像。我不想包含带有标准 Markdown (
![image description](path/to/image)
) 的图像,这在笔记本和常规 rmarkdown 文档中都有效。我也不想使用html。我希望使用 r-code 包含图像可以在笔记本中呈现图像。编辑 :常规 Rmarkdown 文件和笔记本之间的一个区别是笔记本是“预览”而不是编织:
最佳答案
感谢您花时间试用笔记本。今天有一个迂回的方法可以做到这一点;只需制作一个情节并在其上绘制图像。
download.file("https://www.rstudio.com/wp-content/uploads/2014/06/RStudio-Ball.png", "RStudio-Ball.png")
library("png")
ball <- readPNG("RStudio-Ball.png", native = TRUE)
plot(0:1, 0:1, type = "n", ann = FALSE, axes = FALSE)
rasterImage(ball, 0, 0, 1, 1)
不过,这有点 hack,所以我们只是添加了对
knitr::include_graphics
的支持。 .它将在明天的每日(0.99.1272 或更高版本)。
关于r - 使用 knitr::include_graphics() 在 RStudio 笔记本中包含图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38642731/