R (programming language)#Numeric vector
{{Technical|introduction|date=May 2025}}
{{Short description|Programming language for statistics}}
{{About|the programming language|the eighteenth letter of the English alphabet|R|other uses|R (disambiguation)}}
{{Use dmy dates|date=June 2018}}
{{Infobox programming language
| name = R
| logo = R logo.svg
| logo_size = 150px
| screenshot = R terminal.jpg
| screenshot_size = 250px
| screenshot caption = Terminal window for R
| released = {{Start date and age|1993|08}}
| designer = Ross Ihaka and Robert Gentleman
| developer = R Core Team
| typing = Dynamic
| influenced = Julia{{cite web |url=https://docs.julialang.org/en/stable/manual/introduction/#man-introduction-1 |title=Introduction |work=The Julia Manual |access-date=2018-08-05 |archive-url=https://web.archive.org/web/20180620172516/https://docs.julialang.org/en/stable/manual/introduction/#man-introduction-1 |archive-date=20 June 2018 |url-status=dead |df=dmy-all }} pandas{{cite web|url=https://pandas.pydata.org/pandas-docs/stable/getting_started/comparison/comparison_with_r.html|title=Comparison with R|access-date=2024-07-15|work=pandas Getting started}}
| license = GPL-2.0-or-later
| website = {{URL|https://www.r-project.org/|r-project.org}}
| wikibooks = R Programming
| paradigms = Multi-paradigm: procedural, object-oriented, functional, reflective, imperative, array{{cite journal|last1=Morandat|first1=Frances|last2=Hill|first2=Brandon|last3=Osvald|first3=Leo|last4=Vitek|first4=Jan|date=11 June 2012|title=Evaluating the design of the R language: objects and functions for data analysis|url=https://doi.org/10.1007/978-3-642-31057-7_6|journal=European Conference on Object-Oriented Programming|volume=2012|pages=104–131|doi=10.1007/978-3-642-31057-7_6|access-date=2016-05-17|via=SpringerLink|url-access=subscription}}
| latest release version = {{wikidata|property|edit|reference|P348|P548=Q2804309}}
| latest release date = {{start date and age|df=yes|{{wikidata|qualifier|P348|P548=Q2804309|P577}}}}
| latest preview version = {{wikidata|property|edit|reference|P348|P548=Q51930650}}
| latest preview date = {{start date and age|df=yes|{{wikidata|qualifier|P348|P548=Q51930650|P577}}}}
| influenced_by = {{startflatlist}}
- Lisp
- S{{Cite web |last1=Hornik |first1=Kurt |last2=The R Core Team |date=2022-04-12 |title=R FAQ |url=https://cran.r-project.org/doc/FAQ/R-FAQ.html#What-are-the-differences-between-R-and-S_003f |url-status=live |archive-url=https://web.archive.org/web/20221228045640/https://cran.r-project.org/doc/FAQ/R-FAQ.html |archive-date=2022-12-28 |access-date=2022-12-27 |website=The Comprehensive R Archive Network |at=3.3 What are the differences between R and S?}}
- Scheme
{{endflatlist}}
| file_ext = {{Unbulleted list|.r{{Cite web|title=R scripts|url=http://mercury.webster.edu/aleshunas/R_learning_infrastructure/R%20scripts.html|access-date=2021-07-17|website=mercury.webster.edu}}|.rdata|.rhistory|.rds|.rda{{Cite web|date=2017-06-09|title=R Data Format Family (.rdata, .rda)|url=https://www.loc.gov/preservation/digital/formats/fdd/fdd000470.shtml|access-date=2021-07-17|website=Loc.gov}}}}
}}
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.{{Cite journal
|last1=Giorgi
|first1=Federico M.
|last2=Ceraolo
|first2=Carmine
|last3=Mercatelli
|first3=Daniele
|date=2022-04-27
|title=The R Language: An Engine for Bioinformatics and Data Science
|journal=Life
|language=en
|volume=12
|issue=5
|page=648
|doi=10.3390/life12050648
|pmid=35629316
|pmc=9148156
|bibcode=2022Life...12..648G
|doi-access=free }}
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).{{Cite web |title=Home - RDocumentation |url=https://www.rdocumentation.org/ |access-date=2025-06-13 |website=www.rdocumentation.org}}
R is free and open-source software distributed under the GNU General Public License.{{Cite web |title=R - Free Software Directory |url=https://directory.fsf.org/wiki/R#tab=Details |access-date=2024-01-26 |website=directory.fsf.org}}{{Cite web |title=R: What is R? |url=https://www.r-project.org/about.html |access-date=2025-05-10 |website=www.r-project.org}} 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) and Jupyter (a notebook interface).
History
{{Gallery
|title=Co-originators of the R language
|width=160 | height=170 |noborder=yes
|align=center
|footer=
|File:Ross Ihaka (5189180796).jpg
|Ross Ihaka
|alt1=
|File:Robert Gentleman on R Consortium.jpg
|Robert Gentleman
|alt2=
}}
R was started by professors Ross Ihaka and Robert Gentleman as a programming language to teach introductory statistics at the University of Auckland.{{Cite web
|last=Ihaka
|first=Ross
|title=The R Project: A Brief History and Thoughts About the Future
|url=https://www.stat.auckland.ac.nz/~ihaka/downloads/Otago.pdf
|page=12
|url-status=live
|quote=We set a goal of developing enough of a language to teach introductory statistics courses at Auckland.
|archive-url=https://web.archive.org/web/20221228043824/https://www.stat.auckland.ac.nz/~ihaka/downloads/Otago.pdf
|archive-date=2022-12-28
|access-date=2022-12-27}} 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.{{Cite web
|last1=Hornik
|first1=Kurt
|last2=The R Core Team
|date=2022-04-12
|title=R FAQ
|url=https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-is-R-named-R_003f
|url-status=live
|archive-url=https://web.archive.org/web/20221228045640/https://cran.r-project.org/doc/FAQ/R-FAQ.html
|archive-date=2022-12-28
|access-date=2022-12-28
|website=The Comprehensive R Archive Network
|at=2.13 What is the R Foundation?}} In August 1993, Ihaka and Gentleman posted a binary file of R on StatLib — a data archive website.{{Cite web |title=Index of /datasets |url=https://lib.stat.cmu.edu/datasets/ |access-date=2024-09-05 |website=lib.stat.cmu.edu}} At the same time, they announced the posting on the s-news mailing list.{{Cite web
|last=Ihaka
|first=Ross
|title=R: Past and Future History
|url=https://www.stat.auckland.ac.nz/~ihaka/downloads/Interface98.pdf
|url-status=live
|page=4
|archive-url=https://web.archive.org/web/20221228071311/https://www.stat.auckland.ac.nz/~ihaka/downloads/Interface98.pdf
|archive-date=2022-12-28
|access-date=2022-12-28}} On 5 December 1997, R became a GNU project when version 0.60 was released.{{Cite web
|last=Ihaka
|first=Ross
|date=1997-12-05
|title=New R Version for Unix
|url=https://stat.ethz.ch/pipermail/r-announce/1997/000014.html
|url-status=live
|archive-url=https://web.archive.org/web/20230212133422/https://stat.ethz.ch/pipermail/r-announce/1997/000014.html
|archive-date=2023-02-12
|access-date=2023-02-12
|website=stat.ethz.ch}} On 29 February 2000, the 1.0 version was released.{{Cite web
|last=Ihaka
|first=Ross
|title=The R Project: A Brief History and Thoughts About the Future
|url=https://www.stat.auckland.ac.nz/~ihaka/downloads/Otago.pdf
|page=18
|url-status=live
|archive-url=https://web.archive.org/web/20221228043824/https://www.stat.auckland.ac.nz/~ihaka/downloads/Otago.pdf
|archive-date=2022-12-28
|access-date=2022-12-27}}
{{Anchor|CRAN}}Packages
{{Main|R package}}
File:Ggplot2 PlantGrowth violin plot.svg created with the R package ggplot2 for data visualization ]]
R packages are collections of functions, documentation, and data that expand R.{{cite book
| last1 = Wickham
| first1 = Hadley
| last2 = Cetinkaya-Rundel
| first2 = Mine
| last3 = Grolemund
| first3 = Garrett
| title = R for Data Science, Second Edition
| publisher = O'Reilly
| year = 2023
| page = xvii
| isbn = 978-1-492-09740-2
}} For example, packages can add reporting features (using packages such as RMarkdown, Quarto,{{Cite web |title=Quarto |url=https://quarto.org/ |access-date=2024-09-05 |website=Quarto |language=en}} 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.{{Cite journal
|last=Chambers
|first=John M.
|date=2020
|title=S, R, and Data Science
|url=https://journal.r-project.org/archive/2020/RJ-2020-028/index.html
|journal=The R Journal
|language=en
|volume=12
|issue=1
|pages=462–476
|doi=10.32614/RJ-2020-028
|issn=2073-4859
|doi-access=free
|quote=The R language and related software play a major role in computing for data science. ... R packages provide tools for a wide range of purposes and users.}}
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.{{cite book|title=The Book of R: A First Course in Programming and Statistics|first1=Tilman M.|last1=Davies|isbn=9781593276515|year=2016|publisher=No Starch Press|location=San Francisco, California|chapter=Installing R and Contributed Packages|pages=739}}
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",Wickham, Hadley (2014). "Tidy Data" ([https://vita.had.co.nz/papers/tidy-data.pdf PDF]). Journal of Statistical Software. 59 (10). doi:10.18637/jss.v059.i10. which are data contained in a two-dimensional table with a single row for each observation and a single column for each variable.{{cite book |last1=Wickham |first1=Hadley |title=R for Data Science, Second Edition |last2=Cetinkaya-Rundel |first2=Mine |last3=Grolemund |first3=Garrett |publisher=O'Reilly |year=2023 |isbn=978-1-492-09740-2}}
Installing a package occurs only once. For example, to install the tidyverse collection:
> install.packages("tidyverse")
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:{{efn|This code displays to standard error a listing of all the packages that the tidyverse collection depends upon. The code may also display warnings showing namespace conflicts, which may typically be ignored.}}
> # The package name can be enclosed in quotes
> library("tidyverse")
> # But the package name can also be used without quotes
> library(tidyverse)
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).{{Cite journal |last=Hornik |first=Kurt |date=2012 |title=The Comprehensive R Archive Network |url=https://onlinelibrary.wiley.com/doi/10.1002/wics.1212 |journal=WIREs Computational Statistics |language=en |volume=4 |issue=4 |pages=394–398 |doi=10.1002/wics.1212 |issn=1939-5108 |s2cid=62231320|url-access=subscription }} CRAN originally had only three mirror sites and twelve contributed packages.{{cite Q|Q101068595}}. {{As of|2024|10|16}}, it has 99 mirrors{{Cite web |title=The Status of CRAN Mirrors |url=https://cran.r-project.org/mirmon_report.html |access-date=2024-10-16 |website=cran.r-project.org}} and 21,513 contributed packages.{{Cite web |title=CRAN - Contributed Packages |url=https://cran.r-project.org/web/packages/index.html |access-date=2024-10-16 |website=cran.r-project.org}} Packages are also available in repositories such as R-Forge, Omegahat, and GitHub.{{Cite web |title=R-Forge: Welcome |url=https://r-forge.r-project.org/ |access-date=2024-09-05 |website=r-forge.r-project.org}}{{Cite web |title=The Omega Project for Statistical Computing |url=https://www.omegahat.net/ |access-date=2024-09-05 |website=www.omegahat.net}}{{Cite web |title=Build software better, together |url=https://github.com/trending/r |access-date=2024-09-05 |website=GitHub |language=en}}
To provide guidance on the CRAN web site, its [https://cran.r-project.org/web/views/ 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
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.{{efn|Information about conferences and meetings is available in a community-maintained list on GitHub, {{URL|jumpingrivers.github.io/meetingsR/}}}} These groups include:
- UseR!: an annual international R user conference ([https://www.r-project.org/conferences/ website])
- Directions in Statistical Computing (DSC) ([https://www.r-project.org/conferences/ website])
- R-Ladies: an organization to promote gender diversity in the R community ([https://rladies.org website])
- SatRdays: R-focused conferences held on Saturdays ([https://satrdays.org/ website])
- R Conference ([https://rstats.ai/ website])
- posit::conf (formerly known as rstudio::conf) ([https://www.posit.co/conference/ website])
On social media sites such as Twitter, the hashtag #rstats
can be used to follow new developments in the R community.{{Cite book |last=Wickham |first=Hadley |url=https://r4ds.had.co.nz/introduction.html |title=1 Introduction {{!}} R for Data Science |last2=Grolemund |first2=Garrett |date=January 2017 |publisher=O'Reilly Media |year=2017 |isbn=978-1491910399 |edition=1st |language=en}}
Examples
= Hello, World! =
The following is a "Hello, World!" program:
[1] "Hello, World!"Here is an alternative version, which uses the cat()
function:
> cat("Hello, World!")
Hello, World!
= Basic syntax =
The following examples illustrate the basic syntax of the language and use of the command-line interface.{{efn|An expanded list of standard language features can be found in the manual "An Introduction to R", {{URL|cran.r-project.org/doc/manuals/R-intro.pdf}}}}
In R, the generally preferred assignment operator is an arrow made from two characters <-
, although =
can be used in some cases.{{cite web|author=R Development Core Team|title=Assignments with the = Operator|url=https://developer.r-project.org/equalAssign.html|access-date=2018-09-11}}
> x <- 1:6 # Create a numeric vector in the current environment
> y <- x^2 # Similarly, create a 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 transforms 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 then 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 dataframe 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 the new_df dataframe 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 dataframe column Z can be accessed using the syntax $Z, ['Z'], or [3], and the values are the same.
[1] TRUE
> attributes(new_df) # Print information about attributes of the new_df dataframe
$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; this can also be done using the rownames() function
> new_df
X Y Z
one 2 6 12
two 20 30 42
= Structure of a function =
R is able to create functions that add new functionality for code reuse.{{cite web|url=http://www.statmethods.net/management/userfunctions.html|title=Quick-R: User-Defined Functions|first=Robert|last=Kabacoff|year=2012|access-date=2018-09-28|website=statmethods.net}} 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.{{cite web|url=http://adv-r.had.co.nz/Functional-programming.html#closures|title=Advanced R - Functional programming - Closures|website=adv-r.had.co.nz|first=Hadley|last=Wickham}}
The following is an example of creating a function to perform an arithmetic calculation:
- The function, named f, returns a linear combination of x and y.
f <- function(x, y) {
z <- 3 * x + 4 * y
# An explicit return() statement is optional--it could be replaced with simply `z` in this case.
return(z)
}
- As an alternative, the last statement executed in a function is returned implicitly.
f <- function(x, y) 3 * x + 4 * y
The following is some output from using the function defined above:
> f(1, 2) # 3 * 1 + 4 * 2 = 3 + 8
[1] 11
> f(c(1, 2, 3), c(5, 3, 4)) # Element-wise calculation
[1] 23 18 25
> f(1:3, 4) # Equivalent to f(c(1, 2, 3), c(4, 4, 4))
[1] 19 22 25
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:
> `%sumx2y2%` <- function(e1, e2) {e1 ^ 2 + e2 ^ 2}
> 1:3 %sumx2y2% -(1:3)
[1] 2 8 18
Since R version 4.1.0, functions can be written in a short notation, which is useful for passing anonymous functions to higher-order functions:{{cite web|url=https://cran.r-project.org/doc/manuals/r-release/NEWS.html#:~:text=R%20now%20provides%20a%20shorthand%20notation%20for%20creating%20functions|title=NEWS|website=r-project.org}}
> sapply(1:5, \(i) i^2) # here \(i) is the same as function(i)
[1] 1 4 9 16 25
= Native pipe operator =
In R version 4.1.0, a native pipe operator, |>
, was introduced.{{Cite web |title=R: R News |url=https://cran.r-project.org/doc/manuals/r-devel/NEWS.html |access-date=2024-03-14 |website=cran.r-project.org}} This operator allows users to chain functions together, rather than using nested function calls.
> 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 is the use of intermediate objects, rather than the pipe operator:
> mtcars_subset_rows <- subset(mtcars, cyl == 4)
> num_mtcars_subset <- nrow(mtcars_subset_rows)
> print(num_mtcars_subset)
[1] 11
While the pipe operator can produce code that is easier to read, it is advisable to chain together at most 10-15 lines of code using this operator, as well as to chunk code into sub-tasks that are saved into objects having meaningful names.{{Cite book |last=Wickham |first=Hadley |url=https://r4ds.hadley.nz/ |title=R for data science: import, tidy, transform, visualize, and model data |last2=Çetinkaya-Rundel |first2=Mine |last3=Grolemund |first3=Garrett |date=2023 |publisher=O'Reilly |isbn=978-1-4920-9740-2 |edition=2nd |location=Beijing; Sebastopol, CA |chapter=4 Workflow: code style |oclc=on1390607935 |chapter-url=https://r4ds.hadley.nz/workflow-style.html}}
The following is an example having fewer than 10 lines, which some readers may find difficult to grasp in the absence of intermediate named steps:
strsplit(x, "")1 |>
(Vectorize(\(chr) which(chr == key) - 1))() |>
(`+`)(n) |>
(`%%`)(length(key)) |>
(\(i) key[i + 1])() |>
paste(collapse = "")
)("duvFkvFksnvEyLkHAErnqnoyr")The following is a version of the preceding code that is easier to read:
default_key <- c(letters, LETTERS, " ", ":", ")")
f <- function(x, n = 42, key = default_key) {
split_input <- strsplit(x, "")1
results <- (Vectorize(\(chr) which(chr == key) - 1))(split_input) |>
(`+`)(n) |>
(`%%`)(length(key)) |>
(\(i) key[i + 1])()
combined_results <- paste(results, collapse = "")
return(combined_results)
}
f("duvFkvFksnvEyLkHAErnqnoyr")
= 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{{cite web|url=https://stat.ethz.ch/R-manual/R-devel/library/base/html/UseMethod.html|title=Class Methods|access-date=2024-04-25}}
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:
> data <- c("a", "b", "c", "a", NA)
> summary(data)
Length Class Mode
5 character character
> summary(as.factor(data))
a b c NA's
2 1 1 1
= Modeling and plotting =
File:Plots from lm example.svg
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.
- Create x and y values
x <- 1:6
y <- x^2
- Linear regression model: y = A + B * x
model <- lm(y ~ x)
- Display an in-depth 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)
The output from the summary()
function in the preceding code block is as follows:
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 R-squared: 0.9583, Adjusted R-squared: 0.9478
F-statistic: 91.88 on 1 and 4 DF, p-value: 0.000662
= Mandelbrot set =
File:Mandelbrot Creation Animation.gif
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:
install.packages("caTools")
The sample code is as follows:
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 (k in 1: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.{{Cite book |last=Monkman |first=Martin |url=https://bookdown.org/martin_monkman/DataScienceResources_book/r-release-names.html |title=Chapter 5 R Release Names {{!}} Data Science with R: A Resource Compendium}}{{Cite web |last=McGowan |first=Lucy D’Agostino |date=2017-09-28 |title=R release names |url=https://livefreeordichotomize.com/posts/2017-09-28-r-release-names/index.html |access-date=2024-04-07 |website=livefreeordichotomize.com |language=en}}{{Citation |title=r-hub/rversions |date=2024-02-29 |url=https://github.com/r-hub/rversions |access-date=2024-04-07 |publisher=The R-hub project of the R Consortium}}
In 2018, core R developer Peter Dalgaard presented a history of R releases since 1997.{{Cite web |last=Dalgaard |first=Peter |date=2018-07-15 |title=What's in a name? 20 years of R release management |url=https://www.youtube.com/watch?v=z1vTSdRolgI |access-date=2024-04-09 |website=YouTube |format=video}} 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
{{Gallery
|title=Examples of user interfaces for R
|width=160 | height=150 |noborder=yes
|align=center
|footer=
|File:RKWard_screenshot.png
|Screenshot of the RKWard front-end running on the KDE 4 environment
|alt1=
|File:RinEmacswithESS.png
|R running in the emacs editor with the ESS package
|alt2=
|File:RStudio 2023.12.1 Build 402 (256-135).png
|RStudio integrated development environment (IDE)
|mode=packed}}
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{{Cite web |title=R for macOS |url=https://cran.r-project.org/bin/macosx/ |access-date=2024-09-05 |website=cran.r-project.org}} (OSX/macOS only)
- Rattle GUI
- R Commander
- RKWard
- RStudio
- Tinn-R{{Cite web |title=IDE/Editor para Linguagem R {{!}} Tinn-R - Home |url=https://tinn-r.org/en/ |access-date=2024-09-05 |website=Tinn-R |language=pt-br}}
- General-purpose IDEs:
- Eclipse via the [https://marketplace.eclipse.org/content/statet-r/ StatET plugin]
- Visual Studio via R Tools for Visual Studio.
- Source-code editors:
- Emacs
- Vim via the [https://www.vim.org/scripts/script.php?script_id=2628 Nvim-R plugin]
- Kate
- LyX via Sweave
- WinEdt ([https://cran.r-project.org/package=RWinEdt website])
- Jupyter ([https://docs.anaconda.com/anaconda/navigator/tutorials/r-lang/ website])
- Other scripting languages:
- Python ([https://rpy2.github.io website])
- Perl ([https://metacpan.org/module/Statistics::R website])
- Ruby ([https://github.com/alexgutteridge/rsruby source code])
- F# ([https://bluemountaincapital.github.io/FSharpRProvider/ website])
- Julia ([https://github.com/JuliaInterop/RCall.jl source code]).
- General-purpose programming languages:
- Java via the [https://cran.r-project.org/web/packages/Rserve/index.html Rserve socket server]
- .NET C# ([https://rdotnet.github.io/rdotnet/ website])
Statistical frameworks that use R in the background include Jamovi and JASP.{{fact|date=March 2025}}
Implementations
The main R implementation is written primarily in C, Fortran, and R itself. Other implementations include the following:
- [http://www.pqr-project.org pretty quick R] (pqR), by Radford M. Neal, which attempts to improve memory management.
- Renjin for the Java Virtual Machine.
- [https://www.cs.kent.ac.uk/projects/cxxr CXXR] and Riposte{{cite book
|last1=Talbot
|first1=Justin
|last2=DeVito
|first2=Zachary
|last3=Hanrahan
|first3=Pat
|title=Proceedings of the 21st international conference on Parallel architectures and compilation techniques
|chapter=Riposte: A trace-driven compiler and parallel VM for vector code in R
|date=1 January 2012
|pages=43–52
|doi=10.1145/2370816.2370825
|publisher=ACM
|isbn=9781450311823
|s2cid=1989369}} written in C++.
- Oracle's [https://github.com/oracle/fastr FastR] built on [https://www.graalvm.org/ GraalVM].
- TIBCO Enterprise Runtime for R (TERR) to integrate with Spotfire.Jackson, Joab (16 May 2013). [http://www.pcworld.com/article/2038944/tibco-offers-free-r-to-the-enterprise.html TIBCO offers free R to the enterprise]. PC World. Retrieved 20 July 2015. (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.{{cite web
|title=Looking to the future for R in Azure SQL and SQL Server
|date=30 June 2021
|access-date=7 November 2021
|url= https://cloudblogs.microsoft.com/sqlserver/2021/06/30/looking-to-the-future-for-r-in-azure-sql-and-sql-server/}}
Commercial support
{{anchor|Commercialised versions of R|Commercialized versions of R}}
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
Notes
{{Notelist}}
References
{{reflist}}
Further reading
- {{Cite book |last1=Wickham |first1=Hadley |url=https://r4ds.hadley.nz/ |title=R for data science: import, tidy, transform, visualize, and model data |last2=Çetinkaya-Rundel |first2=Mine |last3=Grolemund |first3=Garrett |date=2023 |publisher=O'Reilly |isbn=978-1-4920-9740-2 |edition=2nd |location=Beijing Boston Farnham Sebastopol Tokyo}}
- {{Cite book |last=Gagolewski |first=Marek |year=2024 |isbn=978-0-6455719-2-9 |title=Deep R Programming |url=https://zenodo.org/record/7490464 |language=en |doi=10.5281/ZENODO.7490464}}
External links
- [https://developer.r-project.org/TechDocs/ R Technical Papers]
- [https://www.bigbookofr.com/ Big Book of R], curated list of R-related programming books
- [https://www.r-project.org/doc/bib/R-books.html Books Related to R - R Project], partially annotated curated list of books relating to R or S.
{{R (programming language)}}
{{GNU}}
{{Numerical analysis software}}
{{Statistical software}}
{{Programming languages}}
{{Portal bar|Computer programming}}
{{Authority control}}
Category:Array programming languages
Category:Cross-platform free software
Category:Data mining and machine learning software
Category:Data-centric programming languages
Category:Dynamically typed programming languages
Category:Free plotting software
Category:Free statistical software
Category:Numerical analysis software for Linux
Category:Numerical analysis software for macOS
Category:Numerical analysis software for Windows
Category:Programming languages created in 1993