How to nest knit calls to fix duplicate chunk label errors?

前端 未结 2 1681
悲&欢浪女
悲&欢浪女 2021-01-13 18:02

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

2条回答
  •  遥遥无期
    2021-01-13 18:34

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

提交回复
热议问题