HOWTO · R
How to Check the Version of R
Learn how to check the R version in the R console, from a terminal, and inside an R script, and understand which session or executable each method reports.
On this page
Use R.version.string inside R for a concise version label, or run R --version in a terminal to inspect the executable found on that terminal’s PATH. The console expression describes the R session you opened; the terminal command may refer to a different installation from the one selected by an IDE.
Check the R version in the R console
At the R prompt, evaluate R.version.string to print a short label that includes the release number and any build details. This is usually the quickest way to identify the version used by the current console or RStudio session. The expression reads a value; it does not call a function.
cat(R.version.string, "\n")
Output:
R version 4.2.2 Patched (2022-11-10 r83330)
For structured details, inspect R.version. It is a built-in object, not a function, and its fields describe the R build, including the major and minor components, platform, and version string. Use $ to read a particular field, such as R.version$major, or display the whole object when diagnosing differences between builds. The exact fields and values depend on the R installation, so compare the version string and relevant components instead of relying on a sample tied to another machine.
sessionInfo() answers a broader troubleshooting question. It reports the R version together with the operating system, locale, and attached or loaded package information. Use it when a problem may depend on packages or session setup; use R.version.string when you only need the version label.
Check the R version from the command line
In a terminal, run R --version. This asks the R executable resolved from the current PATH to print its version information. The command is useful on a server or in a shell where you are not opening the graphical console. Its result identifies that executable, not necessarily every R installation on the computer.
If the version printed in the terminal differs from R.version.string in RStudio or another IDE, the two environments are using different R executables. Check which executable the terminal resolves and which installation the IDE is configured to use. A version check can help diagnose package compatibility, but it does not by itself establish which R release a project requires; consult the project’s setup instructions and package requirements before changing installations.
Check the R version in an R script
An R script can print the version that is running it and compare release components against a minimum. getRversion() returns a version value designed for comparisons, so it avoids treating version labels as ordinary text. For example, text sorting can misorder releases such as 4.10 and 4.9; use a version-aware comparison instead.
cat(R.version.string, "\n")
required_version <- "4.0.0"
current_version <- getRversion()
if (current_version >= required_version) {
cat("The required R version is available.\n")
} else {
cat("This script expects R ", required_version, " or later.\n", sep = "")
}
Output:
R version 4.2.2 Patched (2022-11-10 r83330)
The required R version is available.
The required release is an example value; replace it with the minimum supported by your code or project. The script prints the active R version and reports whether that R meets the requirement, leaving the decision about how to install or select R to the project’s environment setup. For a reproducible bug report, include sessionInfo() as well as the version label, since package versions and platform details can affect behavior.