R (programming language)
In-game article clicks load inline without leaving the challenge.
R is a programming language for statistical computing and data visualization. It has been widely adopted in the fields of data mining, bioinformatics, data analysis, and data science.
The core R language is extended by a large number of software packages, which contain reusable code, documentation, and sample data. Some of the most popular R packages are in the tidyverse collection, which enhances functionality for visualizing, transforming, and modelling data, as well as improves the ease of programming (according to the authors and users).
R is free and open-source software distributed under the GNU General Public License. The language is implemented primarily in C, Fortran, and R itself. Precompiled executables are available for the major operating systems (including Linux, MacOS, and Microsoft Windows).
Its core is an interpreted language with a native command line interface. In addition, multiple third-party applications are available as graphical user interfaces; such applications include RStudio (an integrated development environment), Jupyter (a notebook interface), as well as Termux and Google Colab for mobile devices.
History

R was started by professors Ross Ihaka and Robert Gentleman as a programming language to teach introductory statistics at the University of Auckland. The language was inspired by the S programming language, with most S programs able to run unaltered in R. The language was also inspired by Scheme's lexical scoping, allowing for local variables.
The name of the language, R, comes from being both an S language successor and the shared first letter of the authors, Ross and Robert. In August 1993, Ihaka and Gentleman posted a binary file of R on StatLib — a data archive website. At the same time, they announced the posting on the s-news mailing list. On 5 December 1997, R became a GNU project when version 0.60 was released. On 29 February 2000, the 1.0 version was released.
Packages

R packages are collections of functions, documentation, and data that expand R. For example, packages can add reporting features (using packages such as R Markdown, Quarto, knitr, and Sweave) and support for various statistical techniques (such as linear, generalized linear and nonlinear modeling, classical statistical tests, spatial analysis, time-series analysis, and clustering). Ease of package installation and use have contributed to the language's adoption in data science.
Immediately available when starting R after installation, base packages provide the fundamental and necessary syntax and commands for programming, computing, graphics production, basic arithmetic, and statistical functionality.
An example is the tidyverse collection of R packages, which bundles several subsidiary packages to provide a common API. The collection specializes in tasks related to accessing and processing "tidy data", which are data contained in a two-dimensional table with a single row for each observation and a single column for each variable.
Installing a package occurs only once. For example, to install the tidyverse collection:
To load the functions, data, and documentation of a package, one calls the library() function. To load the tidyverse collection, one can execute the following code:
The Comprehensive R Archive Network (CRAN) was founded in 1997 by Kurt Hornik and Friedrich Leisch to host R's source code, executable files, documentation, and user-created packages. CRAN's name and scope mimic the Comprehensive TeX Archive Network (CTAN) and the Comprehensive Perl Archive Network (CPAN). CRAN originally had only three mirror sites and twelve contributed packages. As of 30 June 2025[update], it has 90 mirrors and 22,390 contributed packages. Packages are also available in repositories such as R-Forge, Omegahat, and GitHub.
To provide guidance on the CRAN web site, its area lists packages that are relevant for specific topics; sample topics include causal inference, finance, genetics, high-performance computing, machine learning, medical imaging, meta-analysis, social sciences, and spatial statistics.
The Bioconductor project provides packages for genomic data analysis, complementary DNA, microarray, and high-throughput sequencing methods.
Community

There are three main groups that help support R software development:
- The R Core Team was founded in 1997 to maintain the R source code.
- The R Foundation for Statistical Computing was founded in April 2003 to provide financial support.
- The R Consortium is a Linux Foundation project to develop R infrastructure.
The R Journal is an open access, academic journal that features short to medium-length articles on the use and development of R. The journal includes articles on packages, programming tips, CRAN news, and foundation news.

The R community hosts many conferences and in-person meetups. These groups include:
- UseR!: an annual international R user conference ()
- Directions in Statistical Computing (DSC) ()
- R-Ladies: an organization to promote gender diversity in the R community ()
- SatRdays: R-focused conferences held on Saturdays ()
- Data Science & AI Conferences ()
- posit::conf (formerly known as rstudio::conf) ()
- uRos: an annual conference on the Use of R in Official Statistics ()
On social media sites such as Twitter, the hashtag #rstats can be used to follow new developments in the R community.
Examples
Hello, World!
The following is a "Hello, World!" program:
Here is an alternative version, which uses the cat() function:
Basic syntax
The following examples illustrate the basic syntax of the language and use of the command-line interface.
In R, the generally preferred assignment operator is an arrow made from two characters <-, although = can be used in some cases.
Structure of a function
R can create functions that add new functionality and enable code reuse. Objects created within the body of the function (which are enclosed by curly brackets) remain accessible only from within the function, and any data type may be returned. In R, almost all functions and all user-defined functions are closures.
The following is an example of creating a function to perform an arithmetic calculation:
The following is some output from using the function defined above:
It is possible to define functions to be used as infix operators by using the special syntax `%name%`, where "name" is the function variable name:
Since R version 4.1.0, functions can be written in a short notation (inspired by the lambda calculus), which is useful for passing anonymous functions to higher-order functions:
Native pipe operator
In R version 4.1.0, a native pipe operator, |>, was introduced. This operator allows users to chain functions together, rather than using nested function calls.
An alternative to nested functions is the use of intermediate objects, rather than the pipe operator:
While the pipe operator can produce code that is easier to read, influential R programmers like Hadley Wickham suggest to chain together at most 10-15 lines of code using this operator and saving them into objects having meaningful names to avoid code obfuscation.
Object-oriented programming
The R language has native support for object-oriented programming. There are two native frameworks, the so-called S3 and S4 systems. The former, being more informal, supports single dispatch on the first argument, and objects are assigned to a class simply by setting a "class" attribute in each object. The latter is a system like the Common Lisp Object System (CLOS), with formal classes (also derived from S) and generic methods, which supports multiple dispatch and multiple inheritance
In the example below, summary() is a generic function that dispatches to different methods depending on whether its argument is a numeric vector or a factor:
Modeling and plotting

plot.lm() function). Mathematical notation is allowed in labels, as shown in the lower left plot.The R language has built-in support for data modeling and graphics. The following example shows how R can generate and plot a linear model with residuals.
The output from the summary() function in the preceding code block is as follows:
Mandelbrot set

This example of a Mandelbrot set highlights the use of complex numbers. It models the first 20 iterations of the equation z = z2 + c, where c represents different complex constants.
To run this sample code, it is necessary to first install the package that provides the write.gif() function:
The sample code is as follows:
Version names

All R version releases from 2.14.0 onward have codenames that make reference to Peanuts comics and films.
In 2018, core R developer Peter Dalgaard presented a history of R releases since 1997. Some notable early releases before the named releases include the following:
- Version 1.0.0, released on 29 February 2000, a leap day
- Version 2.0.0, released on 4 October 2004, "which at least had a nice ring to it"
The idea of naming R version releases was inspired by the naming system for Debian and Ubuntu versions. Dalgaard noted an additional reason for the use of Peanuts references in R codenames—the humorous observation that "everyone in statistics is a P-nut."
Interfaces
- Screenshot of the RKWard front-end running on the KDE 4 environment
- R running in the emacs editor with the ESS package
- RStudio integrated development environment (IDE)
R is installed with a command line console by default, but there are multiple ways to interface with the language:
- Integrated development environment (IDE): R.app (OSX/macOS only) Rattle GUI R Commander RKWard RStudio Positron Tinn-R
- General-purpose IDEs: Eclipse via the Visual Studio via R Tools for Visual Studio.
- Source-code editors: Emacs Vim via the Kate LyX via Sweave WinEdt () Jupyter ()
- Other scripting languages: Python () Perl () Ruby () F# () Julia ().
- General-purpose programming languages: Java via the .NET C# ()
Statistical frameworks that use R in the background include Jamovi and JASP.[citation needed]
Implementations
The main R implementation is written primarily in C, Fortran, and R itself. Other implementations include the following:
- (pqR), by Radford M. Neal, which attempts to improve memory management.
- Renjin for the Java Virtual Machine.
- and Riposte written in C++.
- Oracle's built on .
- TIBCO Enterprise Runtime for R (TERR) to integrate with Spotfire. (The company also created S-Plus, an implementation of the S language.)
Microsoft R Open (MRO) was an R implementation. As of 30 June 2021, Microsoft began to phase out MRO in favor of the CRAN distribution.
Commercial support
Although R is an open-source project, some companies provide commercial support:
- Oracle provides commercial support for its Big Data Appliance, which integrates R into its other products.
- IBM provides commercial support for execution of R within Hadoop.
See also
- Comparison of numerical-analysis software
- Comparison of statistical packages
- List of numerical-analysis software
- List of R programming books
- List of R software and tools
- List of statistical software
- Rmetrics
Notes
Further reading
- Wickham, Hadley; Çetinkaya-Rundel, Mine; Grolemund, Garrett (2023). (2nd ed.). Beijing Boston Farnham Sebastopol Tokyo: O'Reilly. ISBN 978-1-4920-9740-2.
- Gagolewski, Marek (2024). . doi:. ISBN 978-0-6455719-2-9.
External links
- , curated list of R-related programming books
- , partially annotated curated list of books relating to R or S.