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:
Error: unexpected '[' in "!["
The my.png
file is in current path. I also tried using absolute path but got the same error message.
Putting above inside the r chuck failed too.
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 .
To add an image in markdown you must stop text editing, and you do this with the command [Alt text] precedeed by a ! Then you have to add the path to the image in brackets. The path to the image is the path from your directory to the image.
To create a new R Presentation you execute the New File -> R Presentation command: After specifying the location to save the presentation, a new presentation will be created and a preview will show within the Presentation tab in the upper right corner of the IDE.
The R package knitr is a general-purpose literate programming engine, with lightweight API's designed to give users full control of the output without heavy coding work. It combines many features into one package with slight tweaks motivated from my everyday use of Sweave.
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.
And R presentation is actually a HTML file like a webpage.
So, just put your image file the same directory with the HTML file, things will work. At least it worked for me.
Just use
![some caption](img_file_name.png)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With