R (programming language)
R is a powerful programming language specifically designed for advanced statistical computing and stunning data visualization. Widely adopted across data mining, bioinformatics, and data science, it empowers users to uncover insights from complex datasets. Its open-source nature and vast ecosystem of packages make it an indispensable tool for researchers and analysts worldwide. R excels in statistical computing and data visualization, serving as a cornerstone for data scientists and researchers worldwide. Its strength lies in its extensive collection of user-contributed packages, constantly expanding its capabilities for diverse analytical tasks. R is a free, open-source project supported by a global community and robust infrastructure, ensuring its continuous evolution and accessibility.
AI Summary
R is a powerful programming language specifically designed for advanced statistical computing and stunning data visualization. Widely adopted across data mining, bioinformatics, and data science, it empowers users to uncover insights from complex datasets. Its open-source nature and vast ecosystem of packages make it an indispensable tool for researchers and analysts worldwide.
- R excels in statistical computing and data visualization, serving as a cornerstone for data scientists and researchers worldwide.
- Its strength lies in its extensive collection of user-contributed packages, constantly expanding its capabilities for diverse analytical tasks.
- R is a free, open-source project supported by a global community and robust infrastructure, ensuring its continuous evolution and accessibility.
What is R?
R is a programming language specifically designed for statistical computing and stunning data visualization. It's the go-to tool for anyone looking to make sense of complex datasets—from scientists unraveling genetic mysteries to analysts predicting market trends.
Its applications span a wide range of fields, including data mining, bioinformatics, and the ever-growing discipline of data science. Think of it as a powerful calculator, a sophisticated charting tool, and a flexible coding environment all rolled into one.
The Heart of R: Packages
What truly sets R apart is its incredible ecosystem of "packages." These are collections of reusable code, documentation, and even sample data, all designed to extend R's core capabilities.
Imagine needing a specific statistical test or a unique type of graph—chances are, someone in the R community has already created a package for it. This collaborative spirit means R is constantly evolving, with new functionalities emerging daily.
One of the most famous collections is the tidyverse, a suite of packages that streamlines data cleaning, transformation, and visualization. It's renowned for making data manipulation more intuitive and programming more enjoyable.
Free and Open for Everyone
R is not just powerful; it's also completely free and open-source software, distributed under the GNU General Public License. This means anyone can download, use, modify, and distribute it without cost.
The language itself is built on solid foundations, primarily implemented in C, Fortran, and even R itself. It runs seamlessly across major operating systems like Linux, macOS, and Windows, making it accessible to virtually anyone with a computer.
Your Gateway to R
While R's core is an interpreted language accessed via a command-line interface, most users interact with it through more user-friendly applications. These often provide a graphical user interface (GUI) or a full integrated development environment (IDE).
The most popular of these is RStudio, a comprehensive IDE that makes coding, debugging, and project management a breeze. Other options include Jupyter notebooks for interactive analysis or mobile-friendly tools like Termux and Google Colab.
From Classroom to Global Tool
R began its journey in the early 1990s, envisioned by professors Ross Ihaka and Robert Gentleman at the University of Auckland. They created it as a teaching tool for introductory statistics, drawing inspiration from the S programming language and Scheme's lexical scoping.
The name "R" is a clever nod to both its predecessor "S" and the shared first letter of its creators, Ross and Robert. From its humble beginnings, R quickly gained traction, becoming a GNU project in 1997 and reaching its 1.0 version in 2000.
The Central Hub: CRAN
The Comprehensive R Archive Network, or CRAN, is the indispensable repository for R. Founded in 1997, it hosts R's source code, executable files, documentation, and—most importantly—thousands of user-created packages.
CRAN has grown exponentially from its initial three mirror sites and twelve packages to over 90 mirrors and tens of thousands of packages today. To help navigate this vast library, CRAN provides "Task Views"—curated lists of packages relevant to specific topics like machine learning, finance, or genetics.
A Thriving Global Community
The R project is backed by a robust community and organizational structure, ensuring its stability and ongoing development. This includes the R Core Team, the R Foundation, and the R Consortium, all working to support R infrastructure and development.
This global community gathers at numerous conferences like "UseR!" and "R-Ladies," promoting diversity and knowledge sharing. On social media, the hashtag #rstats keeps enthusiasts updated on the latest developments.
R in Action: Simple Examples
Let's look at a few basic examples to get a feel for R's syntax. The classic "Hello, World!" program is a great starting point, showing how easily R can produce output.
print("Hello, World!")R uses an arrow (") as its preferred assignment operator, though an equals sign (=) can also work in many contexts. This subtle difference is a common characteristic of R's unique style.
my_variable <- 10
Crafting Functions
Functions are the building blocks of any program, allowing you to encapsulate reusable logic. In R, functions are defined using curly brackets and can return any data type, making them incredibly flexible.
add_numbers <- function(a, b) {
result <- a + b
return(result)
}The Native Pipe Operator
Introduced in R version 4.1.0, the native pipe operator (|>) allows for chaining functions together in a more readable way. Instead of deeply nested calls, you can pass the result of one function directly to the next.
data |> filter(condition) |> group_by(category) |> summarise(mean_value = mean(value))
Data Modeling and Visualization
R's true strength shines in its built-in capabilities for statistical modeling and sophisticated graphics. It can effortlessly generate complex models and visualize their characteristics, making it a favorite among statisticians.
A Nod to Peanuts
Did you know that R's version releases from 2.14.0 onward have delightful codenames? They all reference the classic "Peanuts" comics and films, adding a touch of personality to a powerful statistical tool.
Article
R (programming language)
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 (programming language)
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 (programming language)
A violin plot created with the R package ggplot2 for data visualization
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, 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 Task Views 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
R (programming language)
The R Consortium is one of the three main groups that support R.
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.
UseR! conference is one place the R community can gather at.
The R community hosts many conferences and in-person meetups. These groups include:
• UseR!: an annual international R user conference (website) • Directions in Statistical Computing (DSC) (website) • R-Ladies: an organization to promote gender diversity in the R community (website) • SatRdays: R-focused conferences held on Saturdays (website) • Data Science & AI Conferences (website) • posit::conf (formerly known as rstudio::conf) (website) • uRos: an annual conference on the Use of R in Official Statistics (website)
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
Diagnostic plots for the model from the example code in the "Modeling and plotting" section (q.v. the 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
A Mandelbrot set as visualized in R. (Note: The colours in this image differ from the output of the sample code in the "Mandelbrot set" section.)
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:
Version names
R (programming language)
A CD of R Version 1.0.0, autographed by the core team of R, photographed in Quebec City in 2019
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
R (programming language)
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 StatET plugin • Visual Studio via R Tools for Visual Studio. • Source-code editors: • Emacs • Vim via the Nvim-R plugin • Kate • LyX via Sweave • WinEdt (website) • Jupyter (website) • Other scripting languages: • Python (website) • Perl (website) • Ruby (source code) • F# (website) • Julia (source code). • General-purpose programming languages: • Java via the Rserve socket server • .NET C# (website)
Statistical frameworks that use R in the background include Jamovi and JASP.
Implementations
R (programming language)
The main R implementation is written primarily in C, Fortran, and R itself. Other implementations include the following:
• pretty quick R (pqR), by Radford M. Neal, which attempts to improve memory management. • Renjin for the Java Virtual Machine. • CXXR and Riposte written in C++. • Oracle's FastR built on GraalVM. • 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
R (programming language)
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.