numeric_version
Numeric Versions

### Description

Creates and manipulate version objects, multipart version identifiers of the form 2.17-2.

### Usage

    numeric_version(x, strict = TRUE)
    as.numeric_version(x)
    is.numeric_version(x)
    package_version(x, strict = TRUE)
    is.package_version(x)
    as.package_version(x)
    R_system_version(x, strict = TRUE)
    getRversion()
    [.numeric_version(x, i, j)
    [[.numeric_version(x, ..., exact = NA)
    [[<-.numeric_version(x, ..., value)
    Ops.numeric_version(e1, e2)
    Summary.numeric_version(..., na.rm)
    as.character.numeric_version(x, ...)
    as.data.frame.numeric_version(x, row.names = NULL,
        optional = FALSE, ..., nm = paste(deparse(substitute(x),
        width.cutoff = 500L), collapse = " "))
    c.numeric_version(..., recursive = FALSE)
    duplicated.numeric_version(x, incomparables = FALSE, ...)
    print.numeric_version(x, ..., quote)
    rep.numeric_version(x, ...)
    unique.numeric_version(x, incomparables = FALSE, ...)
    xtfrm.numeric_version(x)
    $.package_version(x, name)
    .encode_numeric_version(x, base = NULL)
    .decode_numeric_version(x, base = NULL)
    .make_numeric_version(x, strict = TRUE, regexp, classes = NULL)

### Arguments

x | a character vector represented as numeric version or package version, or an object of class numeric_version or package_version, or numeric vector for .decode_numeric_version.
strict | a logical value. If TRUE, any invalid version specification causes an error stop.
i, j, exact, value, name | the arguments used in subscripts of an object of numeric_version class. See Subscript for the detailed description.
e1, e2 | at least one of e1 and e2 must be objects inherited from "numeric_version". The other can be objects inherited from the "numeric_version" class or a character vector that can be coerced to the "numeric_version" class.
na.rm | a logical value. If TRUE, NAs should be removed from Summary methods.
row.names, optional, nm, width.cutoff, collapse | the arguments used in the method of generic as.data.frame for class "numeric_version". See as.data.frame for the detailed description. width.cutoff and collapse currently are not used.
recursive | a logical value. If TRUE, combining is done recursively. The default is FALSE.
incomparables | the arguments used in methods of generic duplicated and unique for class "numeric_version". See duplicated and unique for the detailed description.
base | the base value used to encode or decode a numeric version. If it is NULL, by default base is defined as the value of the maximum of unlist of x, plus 1 (that is max(unlist(x)) +1).
regexp | a pattern matching a regular expression in character strings. It is used to check if x is followed the valid version specification.
classes | additional class names attached to the created "numeric_version" object.
quote | this argument is ignored.
... | other optional arguments passed to or from functions/methods.

### Details

An object of "numeric_version" is a list of integer vectors. Each integer vector contains a sequence of integers represented as a numeric version. The valid numeric version string could contain several digits separated by a "." or a "-" character.

- numeric_version() creates a "numeric_version" object by using the utility function .make_numeric_version().
- is.numeric_version() tests if an object is inherited from "numeric_version".
- as.numeric_version() coerces an object to class "numeric_version".

The class "package_version" inherits from class "numeric_version". It is used to represent the version of a package. The valid package version string must contain at least two digits separated by one "." or "-" character. This is different from a valid numeric version string, which can contain only one digit (therefore a "." or a "-" character is not necessary).

- package_version() creates a "package_version" object by using the utility function .make_numeric_version(). If x is a list with the names "major" and "minor", then R_system_version() is used to created an object of class "R_system_version".
- is.package_version() tests if an object is inherited from "package_version".
- as.package_version() coerces an object to class "package_version".

The class "R_system_version" inherits from class "package_version". It is used to represent the system version. The valid system version string must contain exactly three digits separated by two "." characters. R_system_version() creates an object of class "R_system_version" by using the utility function .make_numeric_version().
getRversion() returns the R system version in the object of the class "R_system_version".
You can apply the subscript operators [, [[ and [[<- to the class "numeric_version", and you can apply $ to the class "package_version" to extract or replace part of the object. See Subscript for the detailed description.
The methods of group generic functions Ops and Summary are implemented for the class "numeric_version". All operations are based on the "encoded" numeric version (by using the utility function .encode_numeric_version). The supported Ops operators are:

- <
- >
- !=
- ==
- <=
- >=

The supported Summary functions are:

- min
- max
- range

Other associated methods of generic functions implemented for the class "numeric_version" include as.character, as.data.frame, c, duplicated, print, rep, unique and xtfrm. "xtfrm.numeric_version" returns a numeric vector of the same length as x, as well as attributes "base", "lens" and ".classes". The "base" value is 1 plus the maximum of the un-list of x (that is, max(unlist(x)) +1).
"lens" is a length vector of each component of x. ".classes" contains the class names of x. The [i]th element in returned numeric vector is computed as:

r[i] = sum(x[[i]][1] + x[[i]][2]/base + x[[i]][3]/base^2 +....+ x[[i]][k]/base^(k-1))

where k is the length of the [i]th component of x.
.encode_numeric_version, .decode_numeric_version and .make_numeric_version are utilities to handle the numeric_version objects. .encode_numeric_version and .decode_numeric_version are used to encode and decode the numeric version objects with a specified base value. .make_numeric_version creates a numeric version object by using those valid version strings in x.
Value

numeric_version() | returns an object of class numeric_version.
as.numeric_version() | returns an object of class numeric_version.
.make_numeric_version() | returns an object of class numeric_version.
is.numeric_version() | returns logical TRUE or FALSE.
is.package_version() | returns logical TRUE or FALSE.
Ops.numeric_version() | returns logical TRUE or FALSE.
package_version() | returns an object of class package_version.
as.package_version() | returns an object of class package_version.
R_system_version() | returns an object of class R_system_version.
getRversion() | returns an object of class R_system_version.
extraction operators [, [[, and $ | return the designated elements or properties of the object.
replacement operator [[<- | returns the x but with replaced value in the designated elements or properties.
Summary.numeric_version() | returns the one or two elements of object x.
as.character.numeric_version() | returns a character vector.
as.data.frame.numeric_version() | returns a data frame.
c.numeric_version() | returns an new object of class numeric_version, which list is the combination of all values from all arguments to the function.
duplicated.numeric_version() | returns a logical vector to indicate which elements are duplicates.
print.numeric_version() | returns nothing but prints out the single quoted character format of each element.
rep.numeric_version() | returns an object like x with replicated values.
unique.numeric_version() | returns an object like x but with no duplicate values.
xtfrm.numeric_version | returns a numeric vector of the same length.
.encode_numeric_version() | returns a numeric vector of the same length as x, as well as attributes "base", "lens" and ".classes". The "base" value is the input argument base. The "lens" is a length vector of each component of x. The ".classes" contains the class names of x. The [i]th element in the returned numeric vector is computed as follows: r[i] = sum(x[[i]][1] + x[[i]][2]/base + x[[i]][3]/base^2 +....+ x[[i]][k]/base^(k-1)) where k is the length of the [i]th component of x.
.decode_numeric_version() | returns the decoded numeric version object. (The decoded algorithm could be the reverse of the operation described for .encode_numeric_version.)

Differences between Spotfire Enterprise Runtime for R and Open-source R
The Spotfire Enterprise Runtime for R functions S_system_version() and getSversion() are non-existent in open-source R, but they are similar to open-source R functions R_system_version() and getRversion().
See Also
Subscript, Ops, Summary, as.character, as.data.frame, c, duplicated, print, rep, unique, xtfrm, grepl
Examples

    x.num <- numeric_version(c("2", "2.12.1", "2.13-1", "1-5-1-2"))
    x.num
    x.num > "2.12"
    which(x.num == max(x.num))
    data.frame(Version=x.num)
    ## Not run:  numeric_version(c("1-5-1-2", "1.5$2"))  # "$" is not legal in version
    numeric_version(c("1-5-1-2", "1.5$2"), strict = FALSE) # no error, NA for bad entry
    # package_version needs at least 2 parts
    package_version(c("2", "1-5-1-2"), strict=FALSE)
    # R_system_version needs exactly 3 parts
    R_system_version(c("2.12.1", "2.13-1", "1.13.0", "1.5.1.2", "4"), strict = FALSE)
    getRversion()

Package base version 6.1.5-18
Package Index