R/version.R

Defines functions extract_version typr_version

Documented in typr_version

#' Get installed Typst version
#'
#' @param keep_hash description
#'
#' @returns a version, numeric if `!keep_hash`
#' @export
#'
#' @examplesIf has_any_typst()
#' typr_version()
typr_version <- function(keep_hash = FALSE) {
  vers <- typr_run(args = '--version')$stdout

  if (keep_hash) {
    substr(vers, 7, nchar(vers) - 1)
  } else {
    extract_version(vers)
  }
}

extract_version <- function(x) {
  regmatches(
    x = x,
    m = regexpr(
      pattern = '\\d+.\\d+.\\d+',
      text = x
    )
  )
}

Try the typr package in your browser

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

typr documentation built on June 8, 2025, 10:36 a.m.