Every icon sourced from an installed icon library (as opposed to a local icon_set() or a raw read_icon() file) has a file path of the form <cache root>/<library>/<...name parts...>.svg (see 00_registry.R's icon_fn$get()), which is exactly the library$sub$name expression used to access it. icon_label() recovers that label straight from icon_path() rather than requiring a name to be tracked separately — so, unlike names(), it survives c()/rep()/subsetting on an icons vector (a vctrs rcrd, which cannot carry element names()).

icon_label(x)

Arguments

x

An icons vector.

Value

A character vector the same length as x giving each icon's library$sub$name label. Icons not sourced from an installed library (a local icon_set() or a read_icon() file outside the icon cache) return NA.

Examples

path <- tempfile(fileext = ".svg")
writeLines(
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0"/></svg>',
  path
)
icon_label(read_icon(path)) # NA - not sourced from an installed library
#> [1] NA

if(icon_installed(fontawesome)){

icon_label(fontawesome("rocket", style = "solid"))

}