-
Notifications
You must be signed in to change notification settings - Fork 43
/
save.R
34 lines (34 loc) · 1.03 KB
/
save.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#' Save icons into a local path
#'
#' Store icons in a local directory to simplify sharing of documents containing
#' icons. Bundling icons with your document or app avoids the need for
#' collaborators or servers to have all icons from a library installed.
#'
#' @param icons A named list of icons, the names specify the icon's name in the new icon set.
#' @param path A directory to save the icons into.
#'
#' @export
#' @examples
#' if(icon_installed(fontawesome) && icon_installed(ionicons)){
#'
#' icon_save(
#' list(arrow = fontawesome$solid$`arrow-right`, alarm = ionicons$alarm),
#' path = "icons"
#' )
#'
#' app_icons <- icon_set("icons")
#' app_icons$arrow
#'
#' }
#'
icon_save <- function(icons, path = "."){
stopifnot(is.list(icons))
if(is.null(names(icons))) stop("The icon list must be named to identify the names of icons in the new set.")
mapply(function(x, nm){
writeLines(
format(x),
paste0(file.path(normalizePath(path), nm), ".svg")
)
}, x = icons, nm = names(icons))
invisible(icon_set(path))
}