R (programming language)
Paradigms  Multiparadigm: procedural, objectoriented, functional, reflective, imperative, array 

Designed by  Ross Ihaka and Robert Gentleman 
Developer  R Core Team 
First appeared  August 1993 
Stable release  
Typing discipline  Dynamic 
Platform  arm64 and x8664 
License  GNU GPL v2 
Filename extensions 

Website  www 
Influenced by  
Influenced  
Julia  

R is a programming language for statistical computing and data visualization. It has been adopted in the fields of data mining, bioinformatics, and data analysis.
The core R language is augmented by a large number of extension packages, containing reusable code, documentation, and sample data.
R software is opensource and free software. It is licensed by the GNU Project and available under the GNU General Public License. It is written primarily in C, Fortran, and R itself. Precompiled executables are provided for various operating systems.
As an interpreted language, R has a native command line interface. Moreover, multiple thirdparty graphical user interfaces are available, such as RStudio—an integrated development environment—and Jupyter—a notebook interface.
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 as well as the shared first letter of the authors, Ross and Robert. In August 1993, Ihaka and Gentleman posted a binary of R on StatLib — a data archive website. At the same time, they announced the posting on the snews mailing list. On December 5, 1997, R became a GNU project when version 0.60 was released. On February 29, 2000, the first official 1.0 version was released.
Packages
R packages are collections of functions, documentation, and data that expand R. For example, packages add report features such as RMarkdown, knitr and Sweave. Easy package installation and use have contributed to the language's adoption in data science.
The Comprehensive R Archive Network (CRAN) was founded in 1997 by Kurt Hornik and Fritz Leisch to host R's source code, executable files, documentation, and usercreated packages. Its name and scope mimic the Comprehensive TeX Archive Network and the Comprehensive Perl Archive Network. CRAN originally had three mirrors and 12 contributed packages. As of December 2022, it has 103 mirrors and 18,976 contributed packages. Packages are also available on repositories RForge, Omegahat, and GitHub.
The Task Views on the CRAN website lists packages in fields such as finance, genetics, highperformance computing, machine learning, medical imaging, metaanalysis, social sciences, and spatial statistics.
The Bioconductor project provides packages for genomic data analysis, complementary DNA, microarray, and highthroughput sequencing methods.
Packages add the capability to implement various statistical techniques such as linear, generalized linear and nonlinear modeling, classical statistical tests, spatial analysis, timeseries analysis, and clustering.
An example package is the tidyverse package. Its focus is having a common interface around accessing and processing data contained in the data frame data structure, a twodimensional table of rows and columns. Each function in the package is designed to couple together all the other functions in the package.
Installing a package occurs only once. To install tidyverse:
> install.packages("tidyverse")
To instantiate the functions, data, and documentation of a package, execute the library()
function. To instantiate tidyverse:
> library(tidyverse)
Interfaces
R comes installed with a command line console. Available for installation are various integrated development environments (IDE). IDEs for R include R.app (OSX/macOS only), Rattle GUI, R Commander, RKWard, RStudio, and TinnR.
General purpose IDEs that support R include Eclipse via the StatET plugin and Visual Studio via R Tools for Visual Studio.
Editors that support R include Emacs, Vim via the NvimR plugin, Kate, LyX via Sweave, WinEdt (website), and Jupyter (website).
Scripting languages that support R include Python (website), Perl (website), Ruby (source code), F# (website), and Julia (source code).
General purpose programming languages that support R include Java via the Rserve socket server, and .NET C# (website).
Statistical frameworks which use R in the background include Jamovi and JASP.
Community
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 which features short to mediumlength articles on the use and development of R. It includes articles on packages, programming tips, CRAN news, and foundation news.
The R community hosts many conferences and inperson meetups. These groups include:
 UseR!: an annual international R user conference (website)
 Directions in Statistical Computing (DSC) (website)
 RLadies: an organization to promote gender diversity in the R community (website)
 SatRdays: Rfocused conferences held on Saturdays (website)
 R Conference (website)
 posit::conf (formerly known as rstudio::conf) (website)
Implementations
The main R implementation is written primarily in C, Fortran, and R itself. Other implementations include:
 pretty quick R (pqR), by Radford M. Neal, attempts to improve memory management.
 Renjin is an implementation of R for the Java Virtual Machine.
 CXXR and Riposte are implementations of R written in C++.
 Oracle's FastR is an implementation of R, built on GraalVM.
 TIBCO Software, creator of SPLUS, wrote TERR — an R implementation to integrate with Spotfire.
Microsoft R Open (MRO) was an R implementation. As of 30 June 2021, Microsoft started to phase out MRO in favor of the CRAN distribution.
Commercial support
Although R is an opensource project, some companies provide commercial support:
 Revolution Analytics provides commercial support for Revolution R.
 Oracle provides commercial support for the Big Data Appliance, which integrates R into its other products.
 IBM provides commercial support for inHadoop execution of R.
Examples
Basic syntax
The following examples illustrate the basic syntax of the language and use of the commandline interface. (An expanded list of standard language features can be found in the R manual, "An Introduction to R".)
In R, the generally preferred assignment operator is an arrow made from two characters <
, although =
can be used in some cases.
> x<1:6# Create a numeric vector in the current environment
> y<x^2# Create vector based on the values in x.
> print(y)# Print the vector’s contents.
[1] 1 4 9 16 25 36
> z<x+y# Create a new vector that is the sum of x and y
> z# Return the contents of z to the current environment.
[1] 2 6 12 20 30 42
> z_matrix<matrix(z,nrow=3)# Create a new matrix that turns the vector z into a 3x2 matrix object
> z_matrix
[,1] [,2]
[1,] 2 20
[2,] 6 30
[3,] 12 42
> 2*t(z_matrix)2# Transpose the matrix, multiply every element by 2, subtract 2 from each element in the matrix, and return the results to the terminal.
[,1] [,2] [,3]
[1,] 2 10 22
[2,] 38 58 82
> new_df<data.frame(t(z_matrix),row.names=c('A','B'))# Create a new data.frame object that contains the data from a transposed z_matrix, with row names 'A' and 'B'
> names(new_df)<c('X','Y','Z')# Set the column names of new_df as X, Y, and Z.
> print(new_df)# Print the current results.
X Y Z
A 2 6 12
B 20 30 42
> new_df$Z# Output the Z column
[1] 12 42
> new_df$Z==new_df['Z']&&new_df[3]==new_df$Z# The data.frame column Z can be accessed using $Z, ['Z'], or [3] syntax and the values are the same.
[1] TRUE
> attributes(new_df)# Print attributes information about the new_df object
$names
[1] "X" "Y" "Z"
$row.names
[1] "A" "B"
$class
[1] "data.frame"
> attributes(new_df)$row.names<c('one','two')# Access and then change the row.names attribute; can also be done using rownames()
> new_df
X Y Z
one 2 6 12
two 20 30 42
Structure of a function
One of R's strengths is the ease of creating new functions. Objects in the function body remain local to the function, and any data type may be returned.
Create a function:
# The input parameters are x and y.
# The function returns a linear combination of x and y.
f<function(x,y){
z<3*x+4*y
# this return() statement is optional
return(z)
}
Usage output:
> f(1,2)
[1] 11
> f(c(1,2,3),c(5,3,4))
[1] 23 18 25
> f(1:3,4)
[1] 19 22 25
Native pipe operator
In R version 4.1.0, a native pipe operator, >
, was introduced. This operator allows users to chain functions together one after another, instead of a nested function call.
> nrow(subset(mtcars,cyl==4))# Nested without the pipe character
[1] 11
> mtcars>subset(cyl==4)>nrow()# Using the pipe character
[1] 11
Another alternative to nested functions, in contrast to using the pipe character, is using intermediate objects. However, some argue that using the pipe operator will produce code that is easier to read.
> mtcars_subset_rows<subset(mtcars,cyl==4)
> num_mtcars_subset<nrow(mtcars_subset_rows)
> print(num_mtcars_subset)
[1] 11
Modeling and plotting
The R language has builtin support for data modeling and graphics. The following example shows how R can generate and plot a linear model with residuals.
# Create x and y values
x<1:6
y<x^2
# Linear regression model y = A + B * x
model<lm(y~x)
# Display an indepth summary of the model
summary(model)
# Create a 2 by 2 layout for figures
par(mfrow=c(2,2))
# Output diagnostic plots of the model
plot(model)
Output:
Residuals:
1 2 3 4 5 6 7 8 9 10
3.3333 0.6667 2.6667 2.6667 0.6667 3.3333
Coefficients:
Estimate Std. Error t value Pr(>t)
(Intercept) 9.3333 2.8441 3.282 0.030453 *
x 7.0000 0.7303 9.585 0.000662 ***

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.055 on 4 degrees of freedom
Multiple Rsquared: 0.9583, Adjusted Rsquared: 0.9478
Fstatistic: 91.88 on 1 and 4 DF, pvalue: 0.000662
Mandelbrot set
This Mandelbrot set example highlights the use of complex numbers. It models the first 20 iterations of the equation z = z^{2} + c
, where c
represents different complex constants.
Install the package that provides the write.gif()
function beforehand:
install.packages("caTools")
R Source code:
library(caTools)
jet.colors<
colorRampPalette(
c("green","pink","#007FFF","cyan","#7FFF7F",
"white","#FF7F00","red","#7F0000"))
dx<1500# define width
dy<1400# define height
C<
complex(
real=rep(seq(2.2,1.0,length.out=dx),each=dy),
imag=rep(seq(1.2,1.2,length.out=dy),times=dx)
)
# reshape as matrix of complex numbers
C<matrix(C,dy,dx)
# initialize output 3D array
X<array(0,c(dy,dx,20))
Z<0
# loop with 20 iterations
for (kin1:20){
# the central difference equation
Z<Z^2+C
# capture the results
X[,,k]<exp(abs(Z))
}
write.gif(
X,
"Mandelbrot.gif",
col=jet.colors,
delay=100)
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:
 Version 1.0.0 released on February 2, 2000 (20000229), a leap day
 Version 2.0.0 released on October 4, 2004 (20041004), "which at least had a nice ring to it"
The idea of naming R version releases was inspired by the Debian and Ubuntu version naming system. Dalgaard also noted that another reason for the use of Peanuts references for R codenames is because, "everyone in statistics is a Pnut".
Version  Release date  Name  Peanuts reference  Reference 

4.3.3  20240229  Angel Food Cake  
4.3.2  20231031  Eye Holes  
4.3.1  20230616  Beagle Scouts  
4.3.0  20230421  Already Tomorrow  
4.2.3  20230315  Shortstop Beagle  
4.2.2  20221031  Innocent and Trusting  
4.2.1  20220623  FunnyLooking Kid  
4.2.0  20220422  Vigorous Calisthenics  
4.1.3  20220310  One PushUp  
4.1.2  20211101  Bird Hippie  
4.1.1  20210810  Kick Things  
4.1.0  20210518  Camp Pontanezen  
4.0.5  20210331  Shake and Throw  
4.0.4  20210215  Lost Library Book  
4.0.3  20201010  BunnyWunnies Freak Out  
4.0.2  20200622  Taking Off Again  
4.0.1  20200606  See Things Now  
4.0.0  20200424  Arbor Day  
3.6.3  20200229  Holding the Windsock  
3.6.2  20191212  Dark and Stormy Night  See It was a dark and stormy night#Literature and  
3.6.1  20190705  Action of the Toes  
3.6.0  20190426  Planting of a Tree  
3.5.3  20190311  Great Truth  
3.5.2  20181220  Eggshell Igloos  
3.5.1  20180702  Feather Spray  
3.5.0  20180423  Joy in Playing  
3.4.4  20180315  Someone to Lean On  ^{[better source needed]}  
3.4.3  20171130  KiteEating Tree  See KiteEating Tree and  
3.4.2  20170928  Short Summer  See It Was a Short Summer, Charlie Brown  
3.4.1  20170630  Single Candle  
3.4.0  20170421  You Stupid Darkness  
3.3.3  20170306  Another Canoe  
3.3.2  20161031  Sincere Pumpkin Patch  
3.3.1  20160621  Bug in Your Hair  
3.3.0  20160503  Supposedly Educational  
3.2.5  20160411  Very, Very Secure Dishes  
3.2.4  20160311  Very Secure Dishes  
3.2.3  20151210  Wooden ChristmasTree  See A Charlie Brown Christmas and  
3.2.2  20150814  Fire Safety  
3.2.1  20150618  WorldFamous Astronaut  
3.2.0  20150416  Full of Ingredients  
3.1.3  20150309  Smooth Sidewalk  ^{[page needed]}  
3.1.2  20141031  Pumpkin Helmet  See You're a Good Sport, Charlie Brown  
3.1.1  20140710  Sock it to Me  
3.1.0  20140410  Spring Dance  
3.0.3  20140306  Warm Puppy  
3.0.2  20130925  Frisbee Sailing  
3.0.1  20130516  Good Sport  
3.0.0  20130403  Masked Marvel  
2.15.3  20130301  Security Blanket  
2.15.2  20121026  Trick or Treat  
2.15.1  20120622  Roasted Marshmallows  
2.15.0  20120330  Easter Beagle  
2.14.2  20120229  GiftGetting Season  See It's the Easter Beagle, Charlie Brown and  
2.14.1  20111222  December Snowflakes  
2.14.0  20111031  Great Pumpkin  See It's the Great Pumpkin, Charlie Brown and  
rdevel  N/A  Unsuffered Consequences 
See also
 Comparison of numericalanalysis software
 Comparison of statistical packages
 List of numericalanalysis software
 List of statistical software
 Rmetrics
Further reading
 Wickham, Hadley; ÇetinkayaRundel, Mine; Grolemund, Garrett (2023). R for data science: import, tidy, transform, visualize, and model data (2nd ed.). Beijing Boston Farnham Sebastopol Tokyo: O'Reilly. ISBN 9781492097402.
 Gagolewski, Marek (2024). Deep R Programming. doi:10.5281/ZENODO.7490464. ISBN 9780645571929.
External links
 R Technical Papers
 Free Software Foundation
 R FAQ
 Big Book of R, curated list of Rrelated programming books
 Books Related to R  R Project, partially annotated list of books that are related to S or R and may be useful to the R user community
Portal
Notes
 ^ This displays to standard error a listing of all the packages that tidyverse depends upon. It may also display two errors showing conflict. The errors may be ignored.
 R (programming language)
 Array programming languages
 Crossplatform free software
 Data mining and machine learning software
 Datacentric programming languages
 Dynamically typed programming languages
 Free plotting software
 Free statistical software
 Functional languages
 GNU Project software
 Literate programming
 Numerical analysis software for Linux
 Numerical analysis software for macOS
 Numerical analysis software for Windows
 Programming languages created in 1993
 Science software
 Statistical programming languages