使用Knitr从R块内以编程方式将图像包含在.md文档中 [英] include images programmatically in .md document from within R chunk using knitr
问题描述
我想以编程方式在.Rmd markdown文档中包含很多图像.
I want to programmatically include a lot of images in my .Rmd markdown document. Something like
```{r echo=FALSE}
cat("![](myfile_1.png)")
```
将不起作用,因为最终的.md
输出为
will not work, as the resulting .md
output is
```
## ![](myfile_1.png)
```
我需要摆脱代码标签```
和前导##
.
是否可以选择直接从R块中插入降价代码?
I would need to get rid of the code tags ```
and the leading ##
.
Is there an option to directly inject markdown code from within the R chunk?
BTY:同样的问题也适用于HTML.在这里,从R块中注入HTML代码也会很有帮助.
BTY: The same issue applies to HTML as well. Here also a HTML code injection from within an R chunk would be really helpful.
推荐答案
使用results ='asis'
意味着您不必弄乱钩子,注释等,因为结果不是代码,而是markdown(或其他任何标记)输出格式恰好是)
Using results ='asis'
means that you don't have to mess with the hooks, comments etc as the results are not considered code, but markdown (or whatever the output format happens to be)
```{r myfile-1-plot, echo = F, results = 'asis'}
cat('\n![This is myfile_1.png](myfile1.png)\n')
```
会导致
![This is myfile_1.png](myfile1.png)
请注意,我用新的行标记将输出文本包裹起来,以确保它在单独的行上.
Note that I wrapped the output text with new line markers to ensure that it is on a separate line.
这篇关于使用Knitr从R块内以编程方式将图像包含在.md文档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!