Learn R Programming

smvr (version 0.2.0)

new_pre_release_ids: Pre-release identifiers

Description

A class representing a collection of identifiers, which are used for representing pre-release versions.

There are two functions to create the pre_release_ids vector:

  • pre_release_ids() is a low-level constructor for creating pre-release identifiers from individual components.

  • parse_pre_release_ids() parses a character vector into pre-release identifiers.

Usage

new_pre_release_ids(...)

parse_pre_release_ids(x)

Value

A pre_release_ids vector.

Arguments

...

<dynamic-dots> Single pre-release identifiers. Each identifier can be something to be cast to a pre_release_identifier vector by vctrs::vec_cast(). All components must be of the same length or length 1 (will be recycled).

x

A character vector representing pre-release identifiers. Each identifier separated by a dot (.) will be parsed as a pre_release_identifier.

Limitations

There are some limitations on the number of identifiers in some operations:

  • When comparing with a string, the number of identifiers in the string. If it exceeds 5, an error is raised.

  • When assigning, the number of identifiers in the value being assigned. If it exceeds the number of identifiers in the target or 5, whichever is larger, an error is raised.

Please refer to the examples for details.

Details

If the components are empty, they are treated as the highest precedence pre-release ids, which is used to indicate that the version is not a pre-release version.

Examples

Run this code
# Each components are concatenated with a dot
new_pre_release_ids("rc", 1:3)

ids <- parse_pre_release_ids(
  c("", "alpha.beta", "alpha.1", "beta", "beta.11", "beta.2")
)
ids

# Empty ids have the highest precedence
# (Used to indicate not a pre-release version)
vctrs::vec_sort(ids)

# Can be compared with string notation
ids[ids > "beta.2"]

# Limitations:
# 1. When comparing with a string, the number of identifiers in the string
#    must not exceed 5.
try(ids[ids > "beta.2.3.4.5.6"])

# This works since the string is parsed first.
ids[ids > parse_pre_release_ids("beta.2.3.4.5.6")]

# 2. When assigning, the number of identifiers in the value being assigned
#    must not exceed the number of identifiers in the target or 5,
#    whichever is larger.
try(ids[1] <- parse_pre_release_ids("beta.2.3.4.5.6"))

Run the code above in your browser using DataLab