Debian Codegraph @

man/embed_file.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/markdown.R
3 \name{embed_file}
4 \alias{embed_file}
5 \alias{embed_dir}
6 \alias{embed_files}
7 \title{Embed a file, multiple files, or directory on an HTML page}
8 \usage{
9 embed_file(path, name = basename(path), text = paste("Download", name), ...)
10
11 embed_dir(path, name = paste0(normalize_path(path), ".zip"), ...)
12
13 embed_files(path, name = with_ext(basename(path[1]), ".zip"), ...)
14 }
15 \arguments{
16 \item{path}{Path to the file(s) or directory.}
17
18 \item{name}{The default filename to use when downloading the file. Note that
19 for \code{embed_dir()}, only the base name (of the zip filename) will be used.}
20
21 \item{text}{The text for the hyperlink.}
22
23 \item{...}{For \code{embed_file()}, additional arguments to be passed to
24 \code{\link[=html_tag]{html_tag()}} (e.g., \code{class = 'foo'}). For \code{embed_dir()} and
25 \code{embed_files()}, arguments passed to \code{embed_file()}.}
26 }
27 \value{
28 An HTML tag \samp{<a>} with the appropriate attributes.
29 }
30 \description{
31 For a file, first encode it into base64 data (a character string). Then
32 generate a hyperlink of the form \samp{<a href="base64 data"
33 download="filename">Download filename</a>}. The file can be downloaded when
34 the link is clicked in modern web browsers. For a directory, it will be
35 compressed as a zip archive first, and the zip file is passed to
36 \code{embed_file()}. For multiple files, they are also compressed to a zip file
37 first.
38 }
39 \details{
40 These functions can be called in R code chunks in R Markdown documents with
41 HTML output formats. You may embed an arbitrary file or directory in the HTML
42 output file, so that readers of the HTML page can download it from the
43 browser. A common use case is to embed data files for readers to download.
44 }
45 \note{
46 Windows users may need to install Rtools to obtain the \command{zip}
47 command to use \code{embed_dir()} and \code{embed_files()}.
48 }
49 \examples{
50 logo = xfun:::R_logo()
51 link = xfun::embed_file(logo, text = "Download R logo")
52 link
53 if (interactive()) xfun::html_view(link)
54 }