6.7 Embed arbitrary files in the HTML output file
As mentioned in Section 6.6, we can embed a copy of the Rmd source document in the HTML output file. Sometimes the Rmd source file alone may not be enough to reproduce the report. For example, the report may need an external data file. There is a series of functions in the xfun package that enable you to embed arbitrary files in the HTML output file. To use these functions, make sure you have the following R packages available:
Then you can use one of the functions
xfun::embed_files() in an R code chunk to embed one or multiple files or an entire directory in the HTML output, e.g.,
You can also provide the list of files programmatically, e.g.,
For multiple files, they are first compressed to a zip file, and the zip file will be embedded. These functions return a link, which a reader can click on the HTML page to download the embedded file.
You can learn more technical details behind these functions from the help page
?xfun::embed_file or the blog post at https://yihui.org/en/2018/07/embed-file/.