Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

programmatically find the current version of R

Tags:

r

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).

like image 422
Ben Bolker Avatar asked Sep 17 '15 22:09

Ben Bolker


2 Answers

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"
like image 137
MrFlick Avatar answered Oct 19 '22 14:10

MrFlick


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"
like image 2
Barranka Avatar answered Oct 19 '22 16:10

Barranka