在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;">


注意!

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



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