The file is automatically named by a hash of the object, removing the need to come up with unique file names inside a Quarto report. This has the added benefit of reducing storage needs if the objects needing linking to are identical, and all are stored in the same folder. It also allows the user to download multiple files without worrying about accidentally overwriting them.
# S3 method for default
make_link(
data,
...,
folder = NULL,
file_prefix = NULL,
file_suffix = ".csv",
save_fn = utils::write.csv,
link_prefix = "[download figure data](",
link_suffix = ")"
)String.
Data or object
<data.frame|tbl|obj>
Data frame if using a tabular data save_fn, or possibly any
R object, if a serializing save_fn is provided (e.g. saveRDS()).
Dynamic dots
Arguments forwarded to the corresponding functions that create the elements.
Where to store file
scalar<character> // default: "." (optional)
Defaults to same folder.
File prefix/suffix
scalar<character> // default: "" and ".csv" (optional)
file_suffix should include the dot before the extension.
Saving function
function // default: utils::write.csv
Can be any saving/writing function. However, first argument must be
the object to be saved, and the second must be the path. Hence,
ggplot2::ggsave() must be wrapped in another function with filename and
object swapped. See ggsaver() for an example of such a wrapper function.
Link prefix/suffix
scalar<character> // default: "[download data](" and ")"
The stuff that is returned.
make_link(mtcars, folder = tempdir())
Run the code above in your browser using DataLab