R/source_embed.R

Defines functions embed_file_a

Documented in embed_file_a

#' Embed a file to HTML throght a tag
#'
#' @return
#' @export
#'
embed_file_a <- function(file,
                         name = basename(file),
                         text = paste("Download", name),
                         ...) {
  # Source: https://github.com/yihui/xfun/blob/master/R/markdown.R
  # xfun::embed_file('ddrIntroduction.Rmd')

  # xfun::pkg_load2(c("base64enc", "htmltools", "mime"))

  message('star... paste0')

  h <- paste0(
    "data:",
    mime::guess_type(file),
    ";base64,",
    base64enc::base64encode(file)
  )
  htmltools::a(
    id = "embed-rmd-file",
    href = h,
    download = name,
    hidden = NA,
    text,
    ...
  )
}
BabyMouse/Rb3m documentation built on June 4, 2020, 11:21 a.m.