Conditionally display a block of text in R Markdown

后端 未结 7 1927
一向
一向 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 06:04

    You need a complete R expression, so you cannot break it into multiple blocks like you show, but if the results of a block are a text string then it will be included as is (without quotes), so you should be able to do something like:

    `r if(show.text){"la la la"}`
    

    and it will include the text if and only if show.text is TRUE.

    0 讨论(0)
提交回复
热议问题