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.[7] 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;[8] since August 2021, R ranks 14th in the TIOBE index, a measure of programming language popularity.[9]

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.[1] 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.[10]

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.[11] It was named partly after the first names of the first two R authors and partly as a play on the name of S.[12] In 1995, Martin Maechler convinced Ihaka and Gentleman to make R free and open-source software under the GNU General Public License.[13][14] The R Core Team was formed in 1997 to further develop the language.[12] 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.[15]

The first official release came in 1995.[11] The Comprehensive R Archive Network (CRAN) was officially announced 23 April 1997 with 3 mirrors and 12 contributed packages.[16] The first official "stable beta" version (v1.0) was released on 29 February 2000.[17][18]

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,[citation needed] 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++,[19] Java,[20] .NET[21] or Python code to manipulate R objects directly.[22] 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.[citation needed] Extending it is facilitated by its lexical scoping rules.[23]

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.[24]

R is an interpreted language; users typically access it through a command-line interpreter. If a user types 2+2 at the R command prompt and presses enter, the computer replies with 4.

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.[25] Arrays are stored in column-major order.[26] R's extensible object system includes objects for (among others): regression models, time-series and geo-spatial coordinates. R has no scalar data type.[27] Instead, a scalar is represented as a length-one vector.[28]

Many features of R derive from Scheme. R uses S-expressions to represent both data and code.[citation needed] 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.[29] 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.[30]

R supports procedural programming with functions and, for some functions, object-oriented programming with generic functions.[31] 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 print function that can print almost every class of object in R with print(objectname)[32]

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.[33]

R's capabilities are extended through user-created[34] 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.[35][36][37][38][39] 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.[40]

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),[41] Bioconductor, Omegahat,[42] GitHub, and other repositories.[43][44][45]

The "Task Views" on the CRAN website[46] 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.[47] Microsoft maintains a daily snapshot of CRAN that dates back to Sept. 17, 2014.[48]

Other R package resources include R-Forge,[49] 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.[50]

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).

R is one of 5 languages with an Apache Spark API, along with Scala, Java, Python, and SQL.[51][52]

A list of changes in R releases is maintained in various "news" files at CRAN.[53] Some highlights are listed below for several major releases.

Early developers preferred to run R via the command line console,[62] succeeded by those who prefer an IDE.[63] IDEs for R include (in alphabetical order) Rattle GUI, R Commander, RKWard, RStudio, and Tinn-R.[62] R is also supported in multi-purpose IDEs such as Eclipse via the StatET plugin,[64] and Visual Studio via the R Tools for Visual Studio.[65] Of these, Rstudio is the most commonly used.[63]

Editors that support R include Emacs, Vim (Nvim-R plugin),[66] Kate,[67] LyX,[68] Notepad++,[69] Visual Studio Code, WinEdt,[70] and Tinn-R.[71] Jupyter Notebook can also be configured to edit and run R code.[72]

R functionality is accessible from scripting languages including Python,[73] Perl,[74] Ruby,[75] F#,[76] and Julia.[77] Interfaces to other, high-level programming languages, like Java[78] and .NET C#[79][80] are available.

The main R implementation is written in R, C, and Fortran.[81] 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[82] are implementations of R in C++. Renjin, Riposte, and pqR attempt to improve performance by using multiple cores and deferred evaluation.[83] 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.

TIBCO built a runtime engine called TERR, which is part of Spotfire.[84]

Microsoft R Open (MRO) is a fully compatible R distribution with modifications for multi-threaded computations.[85][86] As of 30 June 2021, Microsoft started to phase out MRO in favor of the CRAN distribution. [87]

R has local communities worldwide for users to network, share ideas, and learn.[88][89]

A growing number of R events bring users together, such as conferences (e.g. useR!, WhyR?, conectaR, SatRdays),[90][91] meetups,[92] as well as R-Ladies groups[93] that promote gender diversity. The R Foundation taskforce focuses on women and other under-represented groups.[94]

The official annual gathering of R users is called "useR!".[95] The first such event was useR! 2004 in May 2004, Vienna, Austria.[96] After skipping 2005, the useR! conference has been held annually, usually alternating between locations in Europe and North America.[97] History:[95]

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.

R is comparable to popular commercial statistical packages such as SAS, SPSS, and Stata. One difference is that R is available at no charge under a free software license.[99]

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.[100] 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".[101]

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.[102]

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.[103] 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.[104] In 2015, Microsoft Corporation acquired Revolution Analytics[105] 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.[106]

In October 2011, Oracle announced the Big Data Appliance, which integrates R, Apache Hadoop, Oracle Linux, and a NoSQL database with Exadata hardware.[107] As of 2012, Oracle R Enterprise[108] became one of two components of the "Oracle Advanced Analytics Option"[109] (alongside Oracle Data Mining).[citation needed]

IBM offers support for in-Hadoop execution of R,[110] and provides a programming model for massively parallel in-database analytics in R.[111]

Mango Solutions offers a validation package for R, ValidR,[113][114] 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.[115]

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".[116])

In R, the generally preferred assignment operator is an arrow made from two characters <-, although = can be used in some cases.[117][118]

# 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 [3] 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.[119] 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.

Diagnostic plots from plotting “model” (q.v. “plot.lm()” function). Notice the mathematical notation allowed in labels (lower left plot).

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:

"Mandelbrot.gif" – graphics created in R with 14 lines of code in Example 2