1

I realize there's another thread with the exact same question, but none of its solutions worked for me. In Rmarkdown, all I need is a way to display/not display a block of text (several pages) depending on a value that r grabbed from an excel book. An answer on the other thread seemed to have potential:

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

But I had issues with this. Firstly, how do I tell it whether to grab this text or not? Secondly, the block of text is littered with instances of `r variable1` and the text.Rmd will not have any of those variables (maybe it will still work anyways?).

Anyways, just like in the other thread, all I need is a way to put a large block of text inside an if statement so if some condition is met, it prints the text, and otherwise, it doesn't. It also cannot output with the grey box around it, in case some solution causes that to occur.

Edit: other thread: Conditionally display a block of text in R Markdown

Edit2:

Here's what I want:

if (var1 == "yes") {

paste("big block of text")

}

The issue with simply doing this is the block of text does not have any of the formatting (ex: #'s in front for headers, bold text, the font is no longer the one I want, and \pagebreak no longer works.) Also, the text is outputted inside the grey box which I definitely don't want.

AnthonyH
  • 105
  • 8
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Include a sample rmarkdown document we can test with. – MrFlick Jan 17 '20 at 16:29
  • 1
    What other posts did you try (you mention "the other thread" but don't link to it), and what about them didn't work? – camille Jan 17 '20 at 16:31
  • Do either of the answers to [this question](https://stackoverflow.com/questions/39550732/is-there-a-way-to-have-conditional-markdown-chunk-execution-in-rmarkdown/39552048#395520488) help? – eipi10 Jan 17 '20 at 16:42

1 Answers1

4

The thread linked by eipi10 had the solution.

Just define soln earlier on as TRUE or FALSE.

r if(!soln) {"\\begin{comment}"}

Big block of text.

r if(!soln) {"\\end{comment}"}

AnthonyH
  • 105
  • 8