R/octicons.R

Defines functions octicon_svg_dest download_octicons

Documented in download_octicons

#' @param version Version of the library
#' @rdname octicons
#' @export
download_octicons <- function(version = "dev"){
  if(version == "dev"){
    version <- "main"
  }
  url <- glue("https://github.com/primer/octicons/archive/refs/heads/{version}.zip")
  meta <- jsonlite::read_json(
    glue("https://raw.githubusercontent.com/primer/octicons/{version}/package.json")
  )

  install_icon_zip(
    "octicons", url, c("icons"),
    svg_pattern = "-16\\.svg$",svg_dest = octicon_svg_dest,
    meta = list(name = "Octicons", version = meta$version, licence = meta$license)
  )

  invisible(octicons)
}

octicon_svg_dest <- function(svgs){
  file <- basename(svgs)
  gsub("-", "_", gsub("-16\\.svg$", "\\.svg", file))
}

#' GitHub's Octicons
#'
#' @param name Name of the icon
#' @rdname octicons
#'
#' @seealso https://primer.style/octicons/
#'
#' @section License:
#' Octicons are distributed under the [MIT License](https://github.com/primer/octicons/blob/main/LICENSE).
#'
#' @return `download_octicons()` invisibly returns the `octicons` icon set
#'   after downloading and installing its SVG files locally.
#'
#'   `octicons(name)` returns an `icons` vector (an SVG tag) for the
#'   requested icon.
#'
#' @export
octicons <- new_icon_set(
  "octicons",
  function(name){
    icon_fn$get(name)
  }
)

Try the icons package in your browser

Any scripts or data that you put into this service are public.

icons documentation built on Sept. 3, 2026, 5:10 p.m.