I\'m running into a duplicate label error when I call a function that uses knit
inside a knit
call. If I label the chunks the problem goes away. Is
I don't understand exactly the context use of your code. Why not to use simply knitr child document feature?
Here a workaround ( hope that someone else come with a better solution specially you if you give more context)
some_function <- function(chunk.name='chunk1'){
knit(text =sprintf("
```{r %s}
1
```
",chunk.name))
}
cat(knit(text ="
```{r }
some_function('a1')
```
```{r }
some_function('a2')
```
"))
You can use knit_child()
instead of knit()
in some_function()
:
library(knitr)
some_function <- function(){
knit_child(text ="
```{r }
1
```
")
}
cat(knit(text ="
```{r }
some_function()
```
```{r }
some_function()
```
"))