Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference the current chunk label in knitr?

Tags:

r

knitr

I want to get the current chunk label inside a chunk. Is this possible?

```{r my_chunk}
gettextf("This chunk is called %s", some_function_to_get_chunk_label())
```
like image 948
nachocab Avatar asked Jul 07 '13 22:07

nachocab


1 Answers

You can use opts_current$get eg...

opts_current$get(name = 'label')

eg

cat(knit(text ="
```{r   'hello'}
render_markdown(strict=TRUE)
opts_current$get(name = 'label')
```
"))

Which gives

render_markdown(strict = TRUE)
opts_current$get(name = "label")

## [1] "hello"
like image 55
mnel Avatar answered Sep 29 '22 07:09

mnel