Skip to content

Instantly share code, notes, and snippets.

@jmbarbone
Created March 7, 2025 19:01
Show Gist options
  • Save jmbarbone/6c23cd35a6d7bc3c891e3b6e3a6dcef2 to your computer and use it in GitHub Desktop.
Save jmbarbone/6c23cd35a6d7bc3c891e3b6e3a6dcef2 to your computer and use it in GitHub Desktop.
pkg_version <- function(package, keep = c("all", "patch", "minor", "major")) {
keep <- match.arg(keep)
version <- utils::packageVersion(package)
version <- unclass(version)[[1L]]
version <- switch(
keep,
all = version,
patch = version[1:3],
minor = version[1:2],
major = version[1L]
)
paste(version, collapse = ".")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment