EVOLUTION-MANAGER
Edit File: embed_file.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Embed a file, multiple files, or directory on an HTML page</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for embed_file {xfun}"><tr><td>embed_file {xfun}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Embed a file, multiple files, or directory on an HTML page</h2> <h3>Description</h3> <p>For a file, first encode it into base64 data (a character string). Then generate a hyperlink of the form <span class="samp"><a href="base64 data" download="filename">Download filename</a></span>. The file can be downloaded when the link is clicked in modern web browsers. For a directory, it will be compressed as a zip archive first, and the zip file is passed to <code>embed_file()</code>. For multiple files, they are also compressed to a zip file first. </p> <h3>Usage</h3> <pre> embed_file(path, name = basename(path), text = paste("Download", name), ...) embed_dir(path, name = paste0(normalize_path(path), ".zip"), ...) embed_files(path, name = with_ext(basename(path[1]), ".zip"), ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>path</code></td> <td> <p>Path to the file(s) or directory.</p> </td></tr> <tr valign="top"><td><code>name</code></td> <td> <p>The default filename to use when downloading the file. Note that for <code>embed_dir()</code>, only the base name (of the zip filename) will be used.</p> </td></tr> <tr valign="top"><td><code>text</code></td> <td> <p>The text for the hyperlink.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>For <code>embed_file()</code>, additional arguments to be passed to <code>htmltools::a()</code> (e.g., <code>class = 'foo'</code>). For <code>embed_dir()</code> and <code>embed_files()</code>, arguments passed to <code>embed_file()</code>.</p> </td></tr> </table> <h3>Details</h3> <p>These functions can be called in R code chunks in R Markdown documents with HTML output formats. You may embed an arbitrary file or directory in the HTML output file, so that readers of the HTML page can download it from the browser. A common use case is to embed data files for readers to download. </p> <h3>Value</h3> <p>An HTML tag <span class="samp"><a></span> with the appropriate attributes. </p> <h3>Note</h3> <p>Windows users may need to install Rtools to obtain the <code>zip</code> command to use <code>embed_dir()</code> and <code>embed_files()</code>. </p> <p>These functions require R packages <span class="pkg">mime</span> and <span class="pkg">htmltools</span>. If you have installed the <span class="pkg">rmarkdown</span> package, these packages should be available, otherwise you need to install them separately. </p> <p>Currently Internet Explorer does not support downloading embedded files (<a href="https://caniuse.com/#feat=download">https://caniuse.com/#feat=download</a>). Chrome has a 2MB limit on the file size. </p> <h3>Examples</h3> <pre> logo = xfun:::R_logo() link = xfun::embed_file(logo, text = "Download R logo") link if (interactive()) htmltools::browsable(link) </pre> <hr /><div style="text-align: center;">[Package <em>xfun</em> version 0.16 <a href="00Index.html">Index</a>]</div> </body></html>