R Programming Language

From arccwiki
Jump to: navigation, search

R overview

R is a programming language used for statistical analysis, data processing, and graphics, including scientific computing.


  • Influenced by S and Scheme
  • Interpreted — interactive or scripted
  • Is free software from GNU project
  • Comes with built-in statistical and graphics functions
  • Additional modules/packages are available for specific purposes

Language features

  • R is case-sensitive
  • Comments are started with '#' and go to the end of the line
  • A command is an expression or an assignment. Commands are separated by ';' or newline. Commands can be grouped by {} into a compound expression.

R for scientific computing

Features of R that are particularly useful for scientific computing include:

  • Useful built-in data types such as vectors, arrays and matrices, with operations on these types that are both more convenient and more efficient than looping over each element
  • Support for values being "not available" or "missing value" in a statistical sense ("NA"), and "Not a Number" ("NaN") such as infinite or numerically undefined
  • A lot of built-in statistical functionality, including linear and nonlinear modeling
  • Built-in graphics/plotting functionality
  • Contributed packages (including scientific) available from CRAN


R itself

R is available for most commonly-used Linux distributions through their package managers from their standard repositories. It is also available for Windows and MacOS. Installation details can be found at R Installation and Administration.

R packages

Installing R packages from CRAN can be done by either of these methods:

  • Download the package source from https://CRAN.R-project.org, unpack it in some directory, and in that directory run a command like:
    sudo R CMD INSTALL <package_name>
    With this method, any dependencies of <package name> must be downloaded and installed first.
  • From within the R interactive environment, run chooseCRANmirror() to interactively select a mirror from which to download packages, then run:
    With this method, the required dependencies of <package name> will be downloaded and installed automatically, for dependencies which are R packages. To access the system location where the package will be installed, R should be run as the root user (Linux) or administrative user (Windows).

Note that some R packages may have dependencies which are system packages and need to be installed by a Linux package manager (like yum or apt) before running install.packages.

R scripts

  • R scripts usually have a .R extension

Here is an example

#! /usr/bin/Rscript

R Semantics & Syntax

R Parallelization Techniques

R User Examples