embed_audio: Embed audio in R Markdown documents

View source: R/utils_embedMediaRMD.R

embed_audioR Documentation

Embed audio in R Markdown documents

Description

embed_audio() provides a standard way to embed audio in R Markdown documents when the output format is HTML, and to print placeholder text when the output format is not HTML.

Usage

embed_audio(
  src,
  type = c("mpeg", "ogg", "wav"),
  attribute = c("controls", "autoplay", "loop", "muted", "preload", "none"),
  id = "",
  placeholder = ""
)

Arguments

src

A path to the media file.

type

The type of media file specified in src.

attribute

A character vector specifying which attributes to use. "none" can be used if no attributes are desired.

id

A character string specifying a unique ID for the element. Can be used by CSS or JavaScript to perform certain tasks for the element with the specific ID.

placeholder

The placeholder text to use when the output format is not HTML.

Details

embed_audio() is a wrapper for the HTML5 <audio> element that prints HTML <audio> code in HTML documents built by R Markdown and placeholder text in non-HTML documents built by R Markdown. This function may be useful for conditional output that depends on the output format. For example, you may embed audio in an R Markdown document when the output format is HTML, and print placeholder text when the output format is LaTeX.

The function determines output format using knitr::is_html_output(). By default, these formats are considered as HTML formats: c('markdown', 'epub', 'html', 'html5', 'revealjs', 's5', 'slideous', 'slidy').

Value

If knitr::is_html_output() is TRUE, returns HTML <audio> code. If knitr::is_html_output() is FALSE, returns placeholder text.

Note

This function is supposed to be used in R code chunks or inline R code expressions. You are recommended to use forward slashes (/) as path separators instead of backslashes in the file paths.


adamleejohnson/R-ajtools documentation built on April 4, 2022, 7:24 a.m.