How to refer to the current block label in knitr?

I want to get the current block label in a piece. Is it possible?

```{r my_chunk} gettextf("This chunk is called %s", some_function_to_get_chunk_label()) ``` 
+6
source share
1 answer

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') ``` ")) 

What gives

 render_markdown(strict = TRUE) opts_current$get(name = "label") ## [1] "hello" 
+6
source

Source: https://habr.com/ru/post/948904/


All Articles