R (programming language)
R is a programming language and free software environment for statistical computing and graphics. It is supported by the R Core Team and the R Foundation for Statistical Computing. It is widely used among statisticians and data miners for developing statistical software and data analysis. Polls, data mining surveys, and studies of scholarly literature databases show that R is highly popular; since August 2021, R ranks 14th in the TIOBE index, a measure of programming language popularity.
The official R software environment is a GNU package. It is written primarily in C, Fortran, and R itself (partially self-hosting) and is available under the GNU General Public License. Precompiled executables are provided for various operating systems. It has a command line interface. Multiple third-party graphical user interfaces are available, such as RStudio, an integrated development environment; and Jupyter, a notebook interface.
R is an implementation of the S programming language combined with lexical scoping semantics. It is inspired by Scheme. S was created by John Chambers in 1976 while at Bell Labs. A commercial version of S was offered as S-PLUS starting in 1988. Many codes written for S-PLUS run unaltered in R.
In 1991 Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, embarked on an S implementation, independent of S-PLUS. They began publicizing it in 1993. It was named partly after the first names of the first two R authors and partly as a play on the name of S. In 1995, Martin Maechler convinced Ihaka and Gentleman to make R free and open-source software under the GNU General Public License. The R Core Team was formed in 1997 to further develop the language. As of 2021, it consisted of Gentleman, Ihaka, and Maechler, plus Douglas Bates, John Chambers, Peter Dalgaard, Kurt Hornik, Tomas Kalibera, Michael Lawrence, Friedrich Leisch, Uwe Ligges, Thomas Lumley, Martin Morgan, Paul Murrell, Martyn Plummer, Brian Ripley, Deepayan Sarkar, Duncan Temple Lang, Luke Tierney, and Simon Urbanek. Heiner Schwarte, Guido Masarotto, Stefano Iacus, Seth Falcon, and Duncan Murdoch were members.
The first official release came in 1995. The Comprehensive R Archive Network (CRAN) was officially announced 23 April 1997 with 3 mirrors and 12 contributed packages. The first official "stable beta" version (v1.0) was released on 29 February 2000.
R and its libraries implement various statistical and graphical techniques, including linear and nonlinear modeling, classical statistical tests, spatial and time-series analysis, classification, clustering, and others. R is easily extensible through functions and extensions, and its community is noted for contributing packages. Many of R's standard functions are written in R, which makes it easy for users to follow the algorithmic choices made. For computationally intensive tasks, C, C++, and Fortran code can be linked and called at run time. Advanced users can write C, C++, Java, .NET or Python code to manipulate R objects directly. R is highly extensible through the use of packages for specific functions and specific applications. Due to its S heritage, R has stronger object-oriented programming facilities than most statistical computing languages. Extending it is facilitated by its lexical scoping rules.
Another of R's strengths is static graphics; it can produce publication-quality graphs that include mathematical symbols. Dynamic and interactive graphics are available through additional packages.
Like languages such as APL and MATLAB, R supports matrix arithmetic. R's data structures include vectors, matrices, arrays, data frames (similar to tables in a relational database) and lists. Arrays are stored in column-major order. R's extensible object system includes objects for (among others): regression models, time-series and geo-spatial coordinates. R has no scalar data type. Instead, a scalar is represented as a length-one vector.
Many features of R derive from Scheme. R uses S-expressions to represent both data and code. Functions are first-class objects and can be manipulated in the same way as data objects, facilitating meta-programming that allows multiple dispatch. Variables in R are lexically scoped and dynamically typed. Function arguments are passed by value, and are lazy—that is to say, they are only evaluated when they are used, not when the function is called.
R supports procedural programming with functions and, for some functions, object-oriented programming with generic functions. A generic function acts differently depending on the classes of the arguments passed to it. In other words, the generic function dispatches the method implementation specific to that object's class. For example, R has a generic
Although used mainly by statisticians and other practitioners seeking an environment for statistical computation and software development, R can also operate as a general matrix calculation toolbox – with performance benchmarks comparable to GNU Octave or MATLAB.
R's capabilities are extended through user-created packages, which allow offer statistical techniques, graphical devices, import/export, reporting (RMarkdown, knitr, Sweave), etc. R's packages and the ease of installing and using them, has been cited as driving the language's widespread adoption in data science. The packaging system is also used by researchers to create compendia to organise research data, code and report files in a systematic way for sharing and archiving.
Multiple packages are included with the basic installation. As of September 2018 more than 15,000 additional packages were available at the Comprehensive R Archive Network (CRAN), Bioconductor, Omegahat, GitHub, and other repositories.
The "Task Views" on the CRAN website lists packages in fields including Finance, Genetics, High Performance Computing, Machine Learning, Medical Imaging, Social Sciences and Spatial Statistics. R has been identified by the FDA as suitable for interpreting data from clinical research. Microsoft maintains a daily snapshot of CRAN that dates back to Sept. 17, 2014.
Other R package resources include R-Forge, a platform for the collaborative development of R packages. The Bioconductor project provides packages for genomic data analysis, including object-oriented data-handling and analysis tools for data from Affymetrix, cDNA microarray, and next-generation high-throughput sequencing methods.
A group of packages called the Tidyverse, which can be considered a "dialect" of the R language, is increasingly popular among developers.[note 1] It strives to provide a cohesive collection of functions to deal with common data science tasks, including data import, cleaning, transformation and visualisation (notably with the ggplot2 package).
A list of changes in R releases is maintained in various "news" files at CRAN. Some highlights are listed below for several major releases.
Early developers preferred to run R via the command line console, succeeded by those who prefer an IDE. IDEs for R include (in alphabetical order) Rattle GUI, R Commander, RKWard, RStudio, and Tinn-R. R is also supported in multi-purpose IDEs such as Eclipse via the StatET plugin, and Visual Studio via the R Tools for Visual Studio. Of these, Rstudio is the most commonly used.
Editors that support R include Emacs, Vim (Nvim-R plugin), Kate, LyX, Notepad++, Visual Studio Code, WinEdt, and Tinn-R. Jupyter Notebook can also be configured to edit and run R code.
R functionality is accessible from scripting languages including Python, Perl, Ruby, F#, and Julia. Interfaces to other, high-level programming languages, like Java and .NET C# are available.
The main R implementation is written in R, C, and Fortran. Several other implementations aimed at improving speed or increasing extensibility. A closely related implementation is pqR (pretty quick R) by Radford M. Neal with improved memory management and support for automatic multithreading. Renjin and are Java implementations of R for use in a Java Virtual Machine. CXXR, rho, and Riposte are implementations of R in C++. Renjin, Riposte, and pqR attempt to improve performance by using multiple cores and deferred evaluation. Most of these alternative implementations are experimental and incomplete, with relatively few users, compared to the main implementation maintained by the R Development Core Team.
Microsoft R Open (MRO) is a fully compatible R distribution with modifications for multi-threaded computations. As of 30 June 2021, Microsoft started to phase out MRO in favor of the CRAN distribution. 
A growing number of R events bring users together, such as conferences (e.g. useR!, WhyR?, conectaR, SatRdays), meetups, as well as R-Ladies groups that promote gender diversity. The R Foundation taskforce focuses on women and other under-represented groups.
The official annual gathering of R users is called "useR!". The first such event was useR! 2004 in May 2004, Vienna, Austria. After skipping 2005, the useR! conference has been held annually, usually alternating between locations in Europe and North America. History:
The R Journal is an open access, refereed journal of the R project. It features short to medium length articles on the use and development of R, including packages, programming tips, CRAN news, and foundation news.
In January 2009, the New York Times ran an article charting the growth of R, the reasons for its popularity among data scientists and the threat it poses to commercial statistical packages such as SAS. In June 2017 data scientist Robert Muenchen published a more in-depth comparison between R and other software packages, "The Popularity of Data Science Software".
R is more procedural than either SAS or SPSS, both of which make heavy use of pre-programmed procedures (called "procs") that are built-in to the language environment and customized by parameters of each call. R generally processes data in-memory, which limits its usefulness in processing larger files.
Although R is an open-source project, some companies provide commercial support and extensions.
In 2007, Richard Schultz, Martin Schultz, Steve Weston and Kirk Mettler founded Revolution Analytics to provide commercial support for Revolution R, their distribution of R, which includes components developed by the company. Major additional components include: ParallelR, the R Productivity Environment IDE, RevoScaleR (for big data analysis), RevoDeployR, web services framework, and the ability for reading and writing data in the SAS file format. Revolution Analytics offers an R distribution designed to comply with established IQ/OQ/PQ criteria that enables clients in the pharmaceutical sector to validate their installation of REvolution R. In 2015, Microsoft Corporation acquired Revolution Analytics and integrated the R programming language into SQL Server, Power BI, Azure SQL Managed Instance, Azure Cortana Intelligence, Microsoft ML Server and Visual Studio 2017.
In October 2011, Oracle announced the Big Data Appliance, which integrates R, Apache Hadoop, Oracle Linux, and a NoSQL database with Exadata hardware. As of 2012, Oracle R Enterprise became one of two components of the "Oracle Advanced Analytics Option" (alongside Oracle Data Mining).
Mango Solutions offers a validation package for R, ValidR, to comply with drug approval agencies, such as the FDA. These agencies required the use of validated software, as attested by the vendor or sponsor.
The following examples illustrate the basic syntax of the language and use of the command-line interface. (An expanded list of standard language features can be found in the R manual, "An Introduction to R".)# Transpose the matrix, multiply every element by 2, subtract 2 from each element in the matrix, and return the results to the terminal.# Create a new data.frame object that contains the data from a transposed z_matrix, with row names 'A' and 'B'# the data.frame column Z can be accessed using $Z, ['Z'], or  syntax, and the values are the same. ## access and then change the row.names attribute; can also be done using rownames()
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. Example:
The R language has built-in support for data modeling and graphics. The following example shows how R can easily generate and plot a linear model with residuals.
Short R code calculating Mandelbrot set through the first 20 iterations of equation z = z2 + c plotted for different complex constants c. This example demonstrates: