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

前端 未结 2 1677
悲&欢浪女
悲&欢浪女 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:38

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

提交回复
热议问题