Numeric Versions

A simple S3 class for representing numeric versions including package versions, and associated methods.

numeric_version(x, strict = TRUE) package_version(x, strict = TRUE) R_system_version(x, strict = TRUE) getRversion()
a character vector with suitable numeric version strings (see ‘Details’); for package_version, alternatively an R version object as obtained by R.version.
a logical indicating whether invalid numeric versions should results in an error (default) or not.

Numeric versions are sequences of one or more non-negative integers, usually (e.g., in package ‘DESCRIPTION’ files) represented as character strings with the elements of the sequence concatenated and separated by single . or - characters. R package versions consist of at least two such integers, an R system version of exactly three (major, minor and patchlevel).

Functions numeric_version, package_version and R_system_version create a representation from such strings (if suitable) which allows for coercion and testing, combination, comparison, summaries (min/max), inclusion in data frames, subscripting, and printing. The classes can hold a vector of such representations.

getRversion returns the version of the running R as an R system version object.

The [[ operator extracts or replaces a single version. To access the integers of a version use two indices: see the examples.

See Also

compareVersion; packageVersion for the version of a specific R package. R.version etc for the version of R (and the information underlying getRversion()).

  • numeric_version
  • as.numeric_version
  • is.numeric_version
  • package_version
  • is.package_version
  • as.package_version
  • R_system_version
  • getRversion
  • [.numeric_version
  • [[.numeric_version
  • [[<-.numeric_version
  • Ops.numeric_version
  • Summary.numeric_version
  • anyNA.numeric_version
  • as.character.numeric_version
  • as.list.numeric_version
  • c.numeric_version
  • duplicated.numeric_version
  • format.numeric_version
  • print.numeric_version
  • rep.numeric_version
  • unique.numeric_version
  • xtfrm.numeric_version
  • $.package_version
  • .encode_numeric_version
  • .decode_numeric_version
  • .make_numeric_version
library(base) x <- package_version(c("1.2-4", "1.2-3", "2.1")) x < "1.4-2.3" c(min(x), max(x)) x[2, 2] x$major x$minor if(getRversion() <= "2.5.0") { ## work around missing feature cat("Your version of R, ", as.character(getRversion()), ", is outdated.\n", "Now trying to work around that ...\n", sep = "") } x[[c(1, 3)]] # '4' as a numeric vector, same as x[1, 3] x[1, 3] # 4 as an integer x[[2, 3]] <- 0 # zero the patchlevel x[[c(2, 3)]] <- 0 # same x x[[3]] <- "2.2.3"; x x <- c(x, package_version("0.0"))[4] <- TRUE stopifnot(identical(, c(rep(FALSE,3), TRUE)), anyNA(x))
Documentation reproduced from package base, version 3.1.3, License: Part of R 3.1.3

Community examples

Looks like there are no examples yet.