Skip to content

Commit

Permalink
❓ Add icon_guess function for better icon finding error
Browse files Browse the repository at this point in the history
Resolves #67
  • Loading branch information
mitchelloharawild committed Aug 10, 2023
1 parent 665fd9c commit 2dbcb3d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/fontawesome.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
10 changes: 1 addition & 9 deletions R/google_material.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
12 changes: 12 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
}

0 comments on commit 2dbcb3d

Please sign in to comment.