我对即将推出的RStudio笔记本电脑感到非常兴奋(可在预览版中找到) RStudio .有关简短概述,请点击此处).但是,我在包含图片时遇到了一些困难.
I am quite excited about the upcoming RStudio notebooks (available in the preview version of RStudio. For a short overview click here). However, I am encountering some difficulties with including images.
在Rmarkdown中,我可以包含以下图像:
In Rmarkdown, I can include images like this:
--- title: "This works" output: html_document --- ```{r echo=FALSE, out.width='10%'} library(knitr) knitr::include_graphics('www.rstudio/wp-content/uploads/2014/06/RStudio-Ball.png') ```
但是,当我想在笔记本上做同样的事情时(请注意从html_document更改为html_notebook),我将不再获得图像:
However, when I want to do the same in a notebook (note the change from html_document to html_notebook), I no longer get an image:
--- title: "This does not work" output: html_notebook --- ```{r echo=FALSE, out.width='10%'} knitr::include_graphics('www.rstudio/wp-content/uploads/2014/06/RStudio-Ball.png') ```
(当我在与笔记本相同的文件夹中使用图像时,仅获得该图像的名称,就像指向外部图像的链接一样).
(When I use an image in the same folder as my notebook, I simply get the name of that image, just as is the case with the link to the external image).
我的问题:有没有办法在rmarkdown代码块内的笔记本(更新:)中显示图像?
请注意:我想使用R代码包含图片.我不想包含带有标准markdown(![image description](path/to/image))的图像,该图像在笔记本和常规rmarkdown文档中均可使用.我也不想使用html.我希望使用r代码包含图像可以在笔记本中呈现图像.
Please note: I want to use r-code to include the image. I do not want to include images with standard markdown (![image description](path/to/image)), which works in both the notebook and the regular rmarkdown document. I also do not want to use html. My hope would be that using r-code to include the image would render the image in the notebook.
编辑:常规Rmarkdown文件和笔记本之间的区别是笔记本是预览版"而不是编织版:
Edit: One difference between regular Rmarkdown files and notebooks is that notebooks are "previewed" and not knit:
推荐答案
感谢您抽出宝贵的时间试用笔记本.您今天可以通过一种环岛的方式来做到这一点.只需绘制一个图并在其上绘制图像即可.
Thanks for taking the time to try out the notebooks. There is a roundabout way you can do this today; just make a plot and draw the image on it.
download.file("www.rstudio/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)但是,这有点骇人听闻,所以我们只添加了对knitr::include_graphics的支持.它将是明天的每天(0.99.1272或更高版本).
It's a bit of a hack, though, so we just added support for knitr::include_graphics. It'll be in tomorrow's daily (0.99.1272 or later).
更多推荐
使用knitr :: include
发布评论