69

There are two R directories on my computer:
one is /home/R-2.15.2,the other is /home/R-2.15.1,
when I input R , I can start R, now I want to know which R is running: 2.15.1 or 2.15.2?

smci
  • 32,567
  • 20
  • 113
  • 146
showkey
  • 482
  • 42
  • 140
  • 295

7 Answers7

73

05/20/2021 Update:

In the R terminal, type R.version.


In addition to @Piotr Jaszkowski, R.Version() should do the work as well

Nav
  • 19,885
  • 27
  • 92
  • 135
yujingz
  • 2,271
  • 1
  • 25
  • 29
39

Run R --version there's info about version on the first line.

Edit: If you ask this question then I bet that R is not running from any of these directories. Check $PATH env variable to get information where binaries are looked for and in which order.

Edit 2: Use type shell command to find where binary for given command is stored, -a for all paths, -f for the hashed one (basically: most recently used).

Piotr Jaszkowski
  • 1,150
  • 9
  • 12
30

The builtin version will show this.

> version
               _                            
platform       x86_64-apple-darwin9.8.0     
...
version.string R version 2.15.2 (2012-10-26)

version is a named list with 14 items, really you just want to see:

> version[['version.string']]
               _                            
[1] "R version 2.15.2 (2012-10-26)"

and in fact if you only want the version-string:

> strsplit(version[['version.string']], ' ')[[1]][3]
[1] "2.15.2"

Type builtins() to see all the builtins.

POSTSCRIPT: turns out version and R.version (mentioned by nathaninmac) are aliases for the same thing.

smci
  • 32,567
  • 20
  • 113
  • 146
  • 1
    It might appear simple, but its output is a 14-part formatted string... – smci Jan 12 '18 at 08:18
  • Following nathaninmac's answer, `paste(version[c("major", "minor")], collapse = ".")` is another way to get the version string `2.15.2` – Josiah Yoder Jul 01 '21 at 16:01
10

Try sessionInfo()

Next to the R version it also returns the versions of the loaded packages and more.

http://stat.ethz.ch/R-manual/R-patched/library/utils/html/sessionInfo.html

Jonas Tundo
  • 6,137
  • 2
  • 35
  • 45
7

This will do the trick as well

paste0(R.Version()[c("major","minor")], collapse = ".")
samssan
  • 393
  • 3
  • 9
1

You can type 'which R' to which R binary gets used

or type R and see something like below, that should tell you which version.

" R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows" Copyright (C) 2012 The R Foundation for Statistical Computing .. .. "

aar cee
  • 239
  • 3
  • 10
0

Nobody listed getRversion() so far, which has the advantage that you can make comparisons with its return value. For example:

getRversion()
#> [1] '4.3.0'
getRversion() >= "4.3.0"
#> [1] TRUE

checkmate::assert_true(getRversion() >= "4.3.0")
checkmate::assert_true(getRversion() >= "4.3.1")
#> Error in eval(expr, envir, enclos): Assertion on 'getRversion() >= "4.3.1"' failed: Must be TRUE.

Created on 2023-06-26 with reprex v2.0.2

hplieninger
  • 3,214
  • 27
  • 32