Skip to contents

A class representing a single pre-release identifier (alphanumeric or numeric) for Semantic Versioning 2.0.0.

Usage

new_pre_release_identifier(x = character())

Arguments

x

Something that can be coerced to a character vector by vctrs::vec_cast(). Empty string ("") is a special case that means no identifier. The default is length 0 character.

Value

A pre_release_identifier vector.

See also

  • pre_release_ids: Whole pre-release identifiers (Concatenation of pre_release_identifier).

Examples

ids <- new_pre_release_identifier(
  c("1", "2", "10", "01", "alpha", "beta", "", NA)
)
ids
#> 1 <numeric>
#> 2 <numeric>
#> 10 <numeric>
#> 01 <alphanumeric>
#> alpha <alphanumeric>
#> beta <alphanumeric>
#> <empty>
#> <NA>

# Numeric identifiers are always sorted before alphanumeric ones.
vctrs::vec_sort(ids)
#> <empty>
#> 1 <numeric>
#> 2 <numeric>
#> 10 <numeric>
#> 01 <alphanumeric>
#> alpha <alphanumeric>
#> beta <alphanumeric>
#> <NA>

# Works with base R vectors.
ids[ids == "alpha" & !is.na(ids)]
#> alpha <alphanumeric>
ids[ids > 2L & !is.na(ids)]
#> 10 <numeric>
#> 01 <alphanumeric>
#> alpha <alphanumeric>
#> beta <alphanumeric>