To determine which version of R you are running when you have multiple versions installed, you can use the following methods:
1. Using R’s Command Line Interface (CLI)
If you’re working in the R console or the R command line interface, simply run the following command:
version
This will display information about the R version you are currently using, along with other details like the platform, language, and operating system.
Example output:
platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status
major 4
minor 1.0
year 2021
month 05
day 18
svn rev 80364
language R
version.string R version 4.1.0 (2021-05-18)
nickname Camp Pontanezen
The version.string
will show the exact version number (in this case, 4.1.0
).
2. From RStudio
If you’re using RStudio, the version of R being used is usually displayed in the Console window upon startup. Alternatively, you can check the version by typing the following command in the RStudio console:
R.version.string
This will give you the version string, like R version 4.1.0 (2021-05-18)
.
3. Using the Terminal (Command Line)
If you have R installed in multiple versions and want to check the version from the terminal, use the following command:
R --version
or
R -v
This will display the version of the R interpreter currently available in the system’s PATH. If you have multiple versions installed and they aren’t available in the same PATH, you might need to specify the full path to the R executable (e.g., /usr/local/bin/R --version
).
4. If Multiple Versions Are Installed
If you have multiple versions of R installed and want to check which one you’re using or test a specific version, you can locate each version by checking its installation directories.
- On Linux/macOS: You can find different versions installed by checking the directories, like
/usr/local/lib/R/
or/opt/R/
. - On Windows: Check the installed versions in
C:\Program Files\R\
.
Then, check the version by running the R --version
or R.version.string
from each directory.
5. Switching Between Versions of R
If you’re using a package manager or version manager for R, like rswitch
or renv
, you can manage and switch between versions more easily.
For example, with rswitch
(on macOS):
rswitch list # List available versions
rswitch use <version> # Switch to the specified version
With renv
(to manage project-specific R environments), you can specify which version of R to use in a given project.