diff --git a/R/fontawesome.R b/R/fontawesome.R index 3ed8c75..fba8d30 100644 --- a/R/fontawesome.R +++ b/R/fontawesome.R @@ -37,7 +37,7 @@ fontawesome <- new_icon_set( "fontawesome", function(name, style = NULL){ if(is.null(style)){ - icon_find(name, "fontawesome")[[1]] + icon_guess(name, "fontawesome") } else { icon_fn$get(c(style, name)) } diff --git a/R/google_material.R b/R/google_material.R index 5ad3136..2c491d4 100644 --- a/R/google_material.R +++ b/R/google_material.R @@ -99,15 +99,7 @@ google_material <- new_icon_set( "google_material", function(name, category = NULL, theme = NULL){ if(is.null(category)){ - x <- icon_find(name, "google_material") - if(is.null(theme)) { - x[[1]] - } else { - if(length(pos <- which(grepl(theme, names(x), fixed = TRUE))) != 1) { - abort("Could not find this specific icon from google_material.") - } - x[[pos]] - } + icon_guess(name, "google_material", pattern = theme) } else { icon_fn$get(c(theme, category, name)) } diff --git a/R/utils.R b/R/utils.R index 098838e..0572195 100644 --- a/R/utils.R +++ b/R/utils.R @@ -88,3 +88,15 @@ install_icon_zip <- function(lib, url, svg_path, svg_pattern = "\\.svg$", return(dl_dir) } + +icon_guess <- function(name, ..., pattern = NULL) { + icon_found <- icon_find(name, ...) + if(!is.null(pattern)) { + icon_found <- icon_found[grepl(pattern, names(icon_found), fixed = TRUE)] + } + + if(rlang::is_empty(icon_found)) { + abort(sprintf("The %s icon could not be found. Perhaps its icon set needs installing or updating?", name)) + } + icon_found[[1]] +}