In R, one can figure out the version of a specific package, and use relational operators on it, with packageVersion()
. For example:
packageVersion("MASS")
(pp <- packageVersion("MASS"))
## [1] ‘7.3.43’
pp > '7.2.0'
## TRUE
How does one get the equivalent form of version information for the running copy of R itself?
To answer this, you have to figure out exactly where to look, which is not as easy as it seems: for example
grep("R[._vV]",apropos("version"),value=TRUE)
## [1] ".ess.ESSRversion" ".ess.Rversion" "getRversion"
## "R_system_version"
## [5] "R.Version" "R.version" "R.version.string"
I'm asking this because I'm frustrated at having to figure it out every few months ... I will answer if no-one else does. Extra credit for elucidating the difference between packageVersion()
and package_version()
...
I think this question is answered in passing here, but the focus of my question is specifically how to get the information in programmatic form (i.e., not just how to find out what version is running, but how to get it in a form suitable for running automated version tests within R).
These are documented in the ?R.Version
help page. It depends on exactly how you want the value formatted/stored really.
packageVersion()
extracts the version info from a particular package as a package_version
object.
package_version()
essentially parses a version number into a package_version
value that can be easily compared.
You can compare versions with
package_version(R.version) > package_version("3.0.1")
or something like that.
The getRversion()
function pointed to in the ?R.Version
help page automatically returns a package_version
object.
getRversion() > package_version("3.0.1")
Plus the package_version
objects can do automatic conversion with conformable strings as well
getRversion() > "3.0.1"
AFAIK, the version
constant gives you that info. In my case:
version
## platform x86_64-pc-linux-gnu
## arch x86_64
## os linux-gnu
## system x86_64, linux-gnu
## status
## major 3
## minor 2.2
## year 2015
## month 08
## day 14
## svn rev 69053
## language R
## version.string R version 3.2.2 (2015-08-14)
## nickname Fire Safety
with(version, paste(major, minor, sep='.'))
## [1] "3.2.2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With