在R演示文稿中添加本地图像文件

[英]add local image file in R presentation


I'm trying to include one imaging file (.png) using R markdown for R presentation. I followed the suggestion from: How to import local image using knitr for markdown but by using ![title](my.png), I get this error:

我正在尝试使用R markdown为R演示文稿包含一个成像文件(.png)。我按照以下建议:如何使用knitr导入本地图像进行降价但是使用![title](my.png),我收到此错误:

Error: unexpected '[' in "!["

错误:意外'['in“![”

The my.png file is in current path. I also tried using absolute path but got the same error message.

my.png文件位于当前路径中。我也尝试使用绝对路径,但得到了相同的错误消息。

Putting above inside the r chuck failed too.

将上方置于r夹头内也失败了。

I also tried

我也试过了

```{r,fig.width=350, fig.height=250,echo=FALSE}
library(png)
library(grid)
appimg <- readPNG('my.png')
grid.raster(appimg)
```

but failed too!

但也失败了!

I am working on windows 7 R studio 0.98.1102 and R 3.2.1 .

我正在使用Windows 7 R studio 0.98.1102和R 3.2.1。

3 个解决方案

#1


10  

After a huge mount of Google search. I finanlly figure out what is the problem.

经过大量的谷歌搜索。我完全弄清楚问题是什么。

The key is that HTML cannot refer local file for security reason. Except that it is a local HTML file, then it can refer local file in the same file directory.

关键是HTML出于安全原因不能引用本地文件。除了它是本地HTML文件,它可以引用同一文件目录中的本地文件。

And R presentation is actually a HTML file like a webpage.

R演示文稿实际上是一个像网页一样的HTML文件。

So, just put your image file the same directory with the HTML file, things will work. At least it worked for me.

因此,只需将您的图像文件与HTML文件放在同一目录中,就可以了。至少它对我有用。

Just use

![some caption](img_file_name.png)

#2


5  

Removing the quotes actually worked for me and note that one better doesn't keep any spaces while naming the image as in use,

删除引号实际上对我有用,请注意,在使用时命名图像时,最好不要保留任何空格,

![title](my_image.png)

Using quotes or having spaces(when renamed) hasn't worked for me in this case.

在这种情况下,使用引号或有空格(重命名时)对我来说不起作用。

#3


2  

If your output format is : slidy_presentation You can use html code:

如果输出格式为:slidy_presentation您可以使用html代码:

<img src="/Users/name/folder/xyz.png";>

Further, if you wish to align and adjust the image to a specific side (say right of your final output and specify a size) you can use something like -

此外,如果您希望将图像对齐并调整到特定的一侧(比如最终输出的右侧并指定尺寸),您可以使用类似的东西 -

<img src="/Users/name/folder/xyz.png"; style="max-width:280px;float:right;">

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/08/07/72039e5ce89322813b148db18392f6c.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告