diff --git a/R/fonts.R b/R/fonts.R index e618c30..5316ac2 100644 --- a/R/fonts.R +++ b/R/fonts.R @@ -68,8 +68,8 @@ validate_user_alias <- function(default_name, family) { cli::cli_abort("{.arg family} must can only include elements named {r_font_faces}") } - is_alias_object <- vapply_lgl(family, is_user_alias) - is_alias_plain <- vapply_lgl(family, is_scalar_character) + is_alias_object <- vapply(family, is_user_alias, logical(1)) + is_alias_plain <- vapply(family, is_scalar_character, logical(1)) is_valid_alias <- is_alias_object | is_alias_plain if (any(!is_valid_alias)) { @@ -84,7 +84,7 @@ validate_user_alias <- function(default_name, family) { obj$file %||% obj$ttf }) - file_exists <- vapply_lgl(files, file.exists) + file_exists <- vapply(files, file.exists, logical(1)) if (any(!file_exists)) { missing <- unlist(files)[!file_exists] cli::cli_abort("Could not find the following font file{?s}: {missing}") diff --git a/R/utils.R b/R/utils.R index 34155b2..71ff361 100644 --- a/R/utils.R +++ b/R/utils.R @@ -18,44 +18,22 @@ plot_dim <- function(dim = c(NA, NA)) { dim } -vapply_chr <- function(.x, .f, ...) { - vapply(.x, .f, character(1), ...) -} -vapply_lgl <- function(.x, .f, ...) { - vapply(.x, .f, logical(1), ...) -} lapply_if <- function(.x, .p, .f, ...) { if (!is.logical(.p)) { - .p <- vapply_lgl(.x, .p) + .p <- vapply(.x, .p, logical(1)) } .x[.p] <- lapply(.x[.p], .f, ...) .x } -keep <- function(.x, .p, ...) { - .x[vapply_lgl(.x, .p, ...)] -} compact <- function(x) { Filter(length, x) } -is_scalar_character <- function(x) { - is.character(x) && length(x) == 1 -} -names2 <- function(x) { - names(x) %||% rep("", length(x)) -} ilapply <- function(.x, .f, ...) { idx <- names(.x) %||% seq_along(.x) out <- Map(.f, names(.x), .x, ...) names(out) <- names(.x) out } -ilapply_if <- function(.x, .p, .f, ...) { - if (!is.logical(.p)) { - .p <- vapply_lgl(.x, .p) - } - .x[.p] <- ilapply(.x[.p], .f, ...) - .x -} set_names <- function(x, nm = x) { stats::setNames(x, nm) }