Conditionally display a block of text in R Markdown

后端 未结 7 1949
一向
一向 2020-12-01 05:12

I am using knitr to parse an R Markdown document . Is there a way to conditionally display a block of text in R Markdown depending on a variable in the environment I pass i

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 05:57

    I find it easiest to do this by putting all of my text into a separate file and then include it from the main file with:

    ```{r conditional_print, child='text.Rmd', eval = show_text}
    ```
    

    This has the advantage that you can still put inline R statements or other chunks into the child file, so that if you change your mind about what counts as optional text, you don't have to refactor your project.

提交回复
热议问题