在我的rmarkdown文件中,我想知道是否有可能进入r块并使用r-chunk本身内的fig.cap选项值. 例如: ```{r fig.cap = 'test'}code..print(options$fig.cap)?```` 在此先感谢任何帮助或建议,从哪里开始寻找 有趣
例如:
```{r fig.cap = 'test'}
code
.
.
print(options$fig.cap)?
````
在此先感谢任何帮助或建议,从哪里开始寻找
有趣的问题.我想知道这样做的正确方法,但这种(非常)hacky方式对我有用.---
output:
html_document:
css: ~/knitr.css
---
```{r, include=FALSE}
library(knitr)
knit_hooks$set(plot = function(x, options) {
fig_fn = paste0(opts_knit$get('base.url'), paste(x, collapse = '.'))
fig.cap <<- knitr:::.img.cap(options)
sprintf("<figure><img src='%s'><figcaption>%s</figcaption></figure>",
fig_fn, fig.cap)
})
```
```{r, fig.cap = 'Figure I: the plot of my figure.'}
plot(1:5)
````
I say some things and some other things.
Oh, yeah please refer to `r fig.cap`
这适用于最近生成的数字,但您可以在数字计数器或其他工作中为每个标题创建唯一变量,以便您可以随时引用.
