parse_semver | R Documentation |
The smvr
class represents versions that follow the
Semantic Versioning Specification (SemVer).
smvr()
is a constructor for creating smvr
objects
from each component.
parse_semver()
parses a character vector into smvr
objects.
parse_semver(x)
smvr(major = integer(), minor = 0L, patch = 0L, pre_release = "", build = "")
x |
A character vector representing semantic versions.
Each version should follow the
Semantic Versioning Specification.
Partial matches are not allowed (e.g., |
major , minor , patch |
Non-negative integers representing
the major, minor, and patch version components.
The default values for |
pre_release |
Something that can be cast to a pre_release_ids vector.
This represents pre-release identifiers, which can be empty ( |
build |
Optional build metadata character vector.
Should have the pattern |
Build metadata is not used for ordering, but the ==
and !=
operators
check it and exactly same build metadata is required for equality.
The other operators (<
, <=
, >
, >=
) ignore build metadata.
A smvr class vector.
# SemVer versions from components
smvr(4, 1:5)
# Parse SemVer versions from character
parse_semver(c("1.0.0-alpha", "1.0.0-beta+exp.sha.5114f85"))
v <- parse_semver(c(
"1.0.0",
"1.0.0-alpha",
"1.0.0-beta",
"1.0.0-rc.1",
"1.0.0-rc.2",
NA
))
v
# Sorting
vctrs::vec_sort(v)
# Works with base R vectors.
v[v >= "1.0.0-rc.2"]
# Partial version components are treated as NA
suppressWarnings(parse_semver("1.5"))
# The numeric_version class supports versions with
# less than 3 components, and can be cast to smvr.
numeric_version("1.5") |>
vctrs::vec_cast(smvr())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.