I am using conditional contents in an R Markdown report as shown here:
```{r setup, echo=FALSE}
show_text <- FALSE
````
`r if(show_text){"this will only be shown when show_text is TRUE"}`
However, I also need to include R variables into the printed content, which cannot be done with the above option.
The only way I have found to do it is using sprintf() in combination with the eval chunk option as follows:
```{r setup, echo=FALSE}
show_text <- TRUE
npages <- 250
````
```{r conditional_block, eval=show_text}
cat(sprintf("The book has %i pages", npages))
```
## The book has 250 pages
But the hashtags in the output makes this option quite ugly for a report.
Is there a cleaner way to do it?
New contributor
Holmes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.