Skip to content

Commit 22a677f

Browse files
committed
update
1 parent a5d3979 commit 22a677f

File tree

4 files changed

+30
-36
lines changed

4 files changed

+30
-36
lines changed

R/insert_audio.R

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#' Insert audio
22
#'
3-
#' @param src URL
4-
#' @param controls boolian
5-
#' @param autoplay boolian
6-
#' @param loop boolian
7-
#' @param muted boolian
8-
#' @param preload character
3+
#' @param src character. It specifies the location (URL) of the audio file.
4+
#' @param controls logical. When \code{TRUE}, it specifies that audio controls should be displayed.
5+
#' @param autoplay logical. When \code{TRUE}, the audio will automatically start playing as soon as it can do so without stopping.
6+
#' @param loop logical. When \code{TRUE}, it specifies that the audio will start over again, every time it is finished.
7+
#' @param muted logical. When \code{TRUE}, it specifies that the audio output should be muted.
8+
#' @param preload character. It specifies if and how the author thinks that the audio file should be loaded when the page loads. Possible values are \code{none}, \code{auto} and \code{metadata}
99
#'
1010
#' @return returns set of html tags
1111
#'
1212
#' @importFrom htmltools tags
13-
#' @importFrom glue glue
1413
#'
1514
#' @author George Moroz <agricolamz@gmail.com>
1615
#' @examples
@@ -29,28 +28,23 @@ insert_audio <- function(src,
2928

3029
preload <- match.arg(preload)
3130

32-
lapply(c(controls, autoplay, loop, muted), function(argument){
31+
arguments <- c(controls = controls,
32+
autoplay = autoplay,
33+
loop = loop,
34+
muted = muted)
35+
36+
lapply(arguments, function(argument){
3337
stopifnot(is.logical(argument))
3438
stopifnot(length(argument) == 1)
3539
})
3640

37-
result <- htmltools::tags$audio(src, preload = preload)
38-
39-
if(controls){
40-
result$attribs <- append(result$attribs, list(controls = NA))
41-
}
42-
43-
if(autoplay){
44-
result$attribs <- append(result$attribs, list(autoplay = NA))
45-
}
46-
47-
if(loop){
48-
result$attribs <- append(result$attribs, list(loop = NA))
49-
}
41+
result <- htmltools::tags$source(src = src) |>
42+
htmltools::tags$audio(preload = preload)
5043

51-
if(muted){
52-
result$attribs <- append(result$attribs, list(loop = NA))
53-
}
44+
result$attribs <- arguments |>
45+
lapply(X = _, function(i){if(i) {NA} else {NULL}}) |>
46+
Filter(x = _, Negate(is.null)) |>
47+
append(values = _, result$attribs)
5448

5549
return(result)
5650
}

man/check_hint.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/check_hints.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/insert_audio.Rd

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)