Include HTML into RMarkdown document

1,284 views
Skip to first unread message

Thibaut

unread,
Feb 14, 2018, 8:29:11 PM2/14/18
to knitr
Hi everyone,

I've been developing a RMarkdown to generate automatic reports.

I succeed to include a HTML file thanks to the include option in the YAML header.

The problem is that I can only choose between 3 options (https://rmarkdown.rstudio.com/html_document_format.html#includes): 
- in_header
- before_body
- or after_body

I'd like to include this HTML file where I want in my RMarkdown document, like in a specific section for example.

Do you know how I can do that?

I found someone with similar problem on Stackoverflow (https://stackoverflow.com/questions/36524238/include-html-files-in-r-markdown-file) but answers did not help me.

Thanks in advance for your help!

Best,
Thibaut

Jeff Newmiller

unread,
Feb 14, 2018, 9:19:36 PM2/14/18
to Thibaut, knitr
Use the results="asis" chunk option and the cat function.  Something like

```{r,results="asis"}
cat( paste( readlines( "yourfilename.html" ), collapse="\n" ) )
```

(sorry, untested)


--
You received this message because you are subscribed to the Google Groups "knitr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knitr+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages