2

I am using bookdown in R. I have some sections I only want to appear in the HTML (gitbook) version (and not the PDF version).

I know about is_html_output(), but that doesn't appear to be what I want, and doesn't work except for very simple bits of text. So this works:

`r if (knitr:::is_html_output())'
## Some text {-}

Things to say to HTML readers.
'
`

But this doesn't (does not compile) because of the tick in don't :

`r if (knitr:::is_html_output())'
## Some text {-}

Things I don't want to say to PDF readers.
'
`

And any R code I wish to place in the chunk fails too.

So while I can use is_html_output(), it very much restricts what I can do.

Is there an easy way to have some text--whole sections, and other large amounts--only visible in the HTML version?

Seems simple... but I can't find a solution. Thanks for help.

P.

1 Answer 1

1

You may consider using child documents, e.g.,

```{r, child = if (knitr::is_html_output()) 'child.Rmd'}

Then you can write arbitrary content in child.Rmd.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.