This function makes it easy to find a version number in an existing set by indexing from another version number. This is particularly useful when you want to know, e.g. what the last development version was before a certain patch version, or what the last minor version was before a certain major version.

search_versions(
  data,
  reference,
  which = length(reference[[1]]),
  increment = -1
)

Arguments

data

Existing version numbers to search

reference

The version number to index from - can be given as a character for convenience.

which

The version number part to be cycled through - can either be supplied as a number or one of the part-names as set in getOption("versionr.parts"). By default this will be the same as the last version number part of reference, giving a more convenient interface. See examples for details.

increment

The number iterations to look forwards/backwards - in most cases this will be -1 to look for the previous version.

Value

A version number

Examples

data <- version_number("1.0.0", "1.2.0", "1.2.0.1", "2.0.0") # Find the previous dev version search_versions(data, "2.0.0", "dev")
#> <version_number[1]> #> [1] 1.2.0.1
# Find the previous patch version search_versions(data, "2.0.0", "patch")
#> <version_number[1]> #> [1] 1.2.0
# In some cases these will be the same: search_versions(data, "1.2.0", "dev")
#> <version_number[1]> #> [1] 1.0.0
search_versions(data, "1.2.0", "patch")
#> <version_number[1]> #> [1] 1.0.0
# If not supplied, the part that gets incremented will be chosen based on # the specificity of the reference number: search_versions(data, "2.0.0.0")
#> <version_number[1]> #> [1] 1.2.0.1
search_versions(data, "2.0.0")
#> <version_number[1]> #> [1] 1.2.0
# You can use different increments, but usually this isn't needed search_versions(data, "2.0.0.0", increment = -2)
#> <version_number[1]> #> [1] 1.2.0
search_versions(data, "1.0.0", increment = 1)
#> <version_number[1]> #> [1] 1.2.0