R Reference

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

The reference material consulted while preparing these pages is listed in the section bibliography.

What R is

R is a language and environment for statistical computing and graphics. The R FAQ describes it as a system made of a language plus a run-time environment with graphics, a debugger, access to certain system functions and the ability to run programs stored in script files. Most of the functions a user calls are themselves written in R, and code that needs speed can call C, C++ or Fortran. Linear and generalized linear models, nonlinear regression, time series, classical tests, clustering, smoothing and a complete graphics system come with the base distribution; thousands of add-on packages on CRAN and Bioconductor extend it (R FAQ 2.1).

R is an implementation of the S language, designed by John Chambers and colleagues at Bell Laboratories and described in Becker, Chambers and Wilks' The New S Language (1988). R looks very much like S, but its implementation and semantics, lexical scoping in particular, come from Scheme (R FAQ 3.1, R FAQ 3.3). Ross Ihaka and Robert Gentleman wrote the first versions at the University of Auckland. Since mid-1997 the R Core Team has maintained the source code, and the R Foundation for Statistical Computing, a not-for-profit organization founded by R Core, holds and administers the copyright of the software and its documentation (R FAQ 2.13, The R Foundation). R is an official part of the GNU project and is free software under the GNU General Public License, version 2 or version 3 (GPL-2 | GPL-3 in the notation of a package’s License field). licence() prints the terms:

licence()
#>
#> This software is distributed under the terms of the GNU General
#> Public License, either Version 2, June 1991 or Version 3, June 2007.
#> The terms of version 2 of the license are in a file called COPYING
#> which you should have received with
#> this software and which can be displayed by RShowDoc("COPYING").
#> Version 3 of the license can be displayed by RShowDoc("GPL-3").
#>
#> Copies of both versions 2 and 3 of the license can be found
#> at https://www.R-project.org/Licenses/.
#>
#> A small number of files (the API header files listed in
#> R_DOC_DIR/COPYRIGHTS) are distributed under the
#> LESSER GNU GENERAL PUBLIC LICENSE, version 2.1 or later.
#> This can be displayed by RShowDoc("LGPL-2.1"),
#> or obtained at the URI given.
#> Version 3 of the license can be displayed by RShowDoc("LGPL-3").
#>
#> 'Share and Enjoy.'

The base distribution has two layers. The base packages (base, utils, stats, methods, graphics, grDevices, grid, tools, parallel, compiler, splines, stats4, datasets and tcltk) are part of R itself and versioned with it. The recommended packages (MASS, Matrix, lattice, survival, nlme, mgcv, codetools, foreign and a few more) are maintained separately on CRAN but shipped with every binary build. Everything else is an add-on package that you install from CRAN, Bioconductor or another repository; Packages, Libraries and Namespaces explains libraries and the search path.

This section teaches the language, its base packages and the tooling around it, from a first Rscript to a package on CRAN. Its statistics and graphics pages document what a learner of the language needs to read and fit models and draw charts; they are not a statistics course.

Version baseline

The section targets R 4.6: every page was checked against R 4.6.1 ("Happy Hop", released on 2026-06-24), the current release and the version every r-release manual describes. R 4.6.0 came out on 2026-04-24. R has one x.y.0 release a year, in spring, followed by patch releases as needed and a final patch of the old series shortly before the next x.y.0 (R Developer Page). Re-checked on 2026-10-22: R 4.6.2 ("Diversified Portfolio") is at release-candidate stage (code freeze on 2026-10-22) and is scheduled for 2026-10-29; the source releases still end at R 4.6.1. The development version, R-devel, will become R 4.7.0, with no release date published; the few R-devel changes that matter to a learner are described as upcoming on What’s New and Migrating Older Code.

R.version.string
#> [1] "R version 4.6.1 (2026-06-24)"
getRversion() >= "4.6.0"
#> [1] TRUE

How the pages were checked:

  • Every example on every page is a complete script that was run with Rscript on R 4.6.1 (in a throwaway container) and passed lintr::lint() with the default linters (a line that deliberately shows a bad idiom carries a # nolint comment). The #> lines are the real output, reprex-style; output that depends on the machine (paths, platform strings, timings) is trimmed or replaced, and the page says so. Code that cannot run in a container, such as the RStudio and Positron user interfaces, the Windows and macOS installers or a CRAN submission, was checked against the official documentation and is labelled as not run.

  • The code uses the current idioms: the native pipe |>, the \(x) lambda shorthand, vapply() with a declared result, seq_along() and TRUE/FALSE. Where older tutorials teach something else (magrittr’s %>% as the only pipe, stringsAsFactors = TRUE, T and F, sapply() everywhere, 1:length(x)), the page explains the difference in prose.

  • Add-on packages change faster than R. Each page that uses one states the version it was checked against in its introduction instead of hard-coding versions in the prose. S7 is described as the CRAN package it is today (0.2.2), not as part of base R.

  • Every concept is drawn from the official R documentation: the six manuals, the R FAQ, the help pages of the base and recommended packages, NEWS and the R Blog, and, for add-on packages, each package’s own documentation, labelled as package documentation. Each example is followed by a Source: link, and every source is listed in the Bibliography.

The shelf scenario

The examples across the section share one small, original domain: shelf, a library catalogue seen from the analysis side. It is the domain of the Rust Reference, the Go Reference and the Ruby Reference too, so the same data can be compared across languages.

  • books is a 16-row data frame read with read.csv("books.csv"): title, author, isbn, year, genre and pages, with deliberate mess for the cleaning pages (stray blanks, two spellings of one author, genre variants, an empty ISBN, one with a wrong check digit, and missing years and page counts).

  • loans has 60 loans (loan_id, isbn, member, loan_date, return_date) from January 2025 to June 2026, including an impossible date, a return before its loan, a member written two ways and seven loans still out.

  • shelf_today is fixed at 2026-06-30 and loan_days at 21, so overdue results are reproducible.

  • A book S3 class (constructor, validator, helper and print, format and summary methods) is re-modelled as an S4 class, an R6 class and an S7 class on the object-oriented pages.

  • The analyses are loans per month, overdue rates by genre, the distribution of loan durations and a model of loan duration on pages and genre, drawn with base graphics, lattice and ggplot2.

  • On the tooling pages the code becomes a small shelf package with roxygen2 documentation, testthat tests and a vignette, then an Rscript command-line report, a Shiny dashboard and a plumber API.

Pure-statistics pages also use the built-in data sets (penguins from R 4.5.0, mtcars, airquality). The pages build on each other, and the cheat sheet summarises the whole section.

Getting the scenario files

The scripts on the other pages start with source("scenario.R"). To run them, download these three files into one directory and make it R’s working directory with setwd() or an RStudio or Positron project. To keep the two CSV files somewhere else, set the SHELF_DIR environment variable to their directory before sourcing the script.

  • scenario.R: reads the two files into books and loans, and defines shelf_today, loan_days and the book S3 class.

  • books.csv: the 16 books.

  • loans.csv: the 60 loans.

scenario.R
# The shelf scenario: data frames and the `book` S3 class shared by every page.
# Usage: save this file, books.csv and loans.csv in your working directory,
# then run source("scenario.R"). Set the SHELF_DIR environment variable to
# read the two CSV files from another directory.

shelf_dir <- Sys.getenv("SHELF_DIR", unset = ".")
shelf_today <- as.Date("2026-06-30")
loan_days <- 21L

# --- data frames ----------------------------------------------------------

books <- read.csv(file.path(shelf_dir, "books.csv"))

loans <- read.csv(file.path(shelf_dir, "loans.csv"), colClasses = "character")
loans$loan_date <- as.Date(loans$loan_date, format = "%Y-%m-%d")
loans$return_date <- as.Date(loans$return_date, format = "%Y-%m-%d")

# --- the book S3 class ----------------------------------------------------

normalise_isbn <- function(x) {
  gsub("[^0-9X]", "", toupper(x))
}

is_valid_isbn13 <- function(x) {
  digits <- normalise_isbn(x)
  ok <- nchar(digits) == 13L & !grepl("X", digits, fixed = TRUE)
  vapply(seq_along(digits), \(i) {
    if (!ok[[i]]) {
      return(FALSE)
    }
    d <- as.integer(strsplit(digits[[i]], "")[[1L]])
    sum(d * rep(c(1L, 3L), length.out = 13L)) %% 10L == 0L
  }, logical(1L))
}

new_book <- function(title = character(), author = character(),
                     isbn = character(), year = integer(),
                     genre = character(), pages = integer()) {
  stopifnot(
    is.character(title), is.character(author), is.character(isbn),
    is.integer(year), is.character(genre), is.integer(pages)
  )
  structure(
    list(
      title = title, author = author, isbn = isbn,
      year = year, genre = genre, pages = pages
    ),
    class = "book"
  )
}

validate_book <- function(x) {
  fields <- unclass(x)
  if (any(lengths(fields) != 1L)) {
    stop("every field of a book must have length 1", call. = FALSE)
  }
  if (is.na(fields$title) || !nzchar(fields$title)) {
    stop("a book needs a title", call. = FALSE)
  }
  if (!is.na(fields$isbn) && !is_valid_isbn13(fields$isbn)) {
    stop("invalid ISBN-13: ", fields$isbn, call. = FALSE)
  }
  if (!is.na(fields$year) && fields$year > 2100L) {
    stop("implausible year: ", fields$year, call. = FALSE)
  }
  x
}

book <- function(title, author = NA_character_, isbn = NA_character_,
                 year = NA_integer_, genre = NA_character_,
                 pages = NA_integer_) {
  validate_book(new_book(
    title = trimws(title),
    author = trimws(author),
    isbn = if (is.na(isbn)) isbn else normalise_isbn(isbn),
    year = as.integer(year),
    genre = trimws(genre),
    pages = as.integer(pages)
  ))
}

format.book <- function(x, ...) {
  year <- if (is.na(x$year)) "n.d." else x$year
  sprintf("%s (%s, %s)", x$title, x$author, year)
}

print.book <- function(x, ...) {
  cat("<book>", format(x), "\n")
  invisible(x)
}

summary.book <- function(object, ...) {
  structure(
    list(
      title = object$title,
      has_isbn = !is.na(object$isbn),
      pages = object$pages
    ),
    class = "summary.book"
  )
}

print.summary.book <- function(x, ...) {
  cat("Book:", x$title, "\n")
  cat("ISBN known:", x$has_isbn, "\n")
  cat("Pages:", if (is.na(x$pages)) "unknown" else x$pages, "\n")
  invisible(x)
}
books.csv
"title","author","isbn","year","genre","pages"
"The Dispossessed","Ursula K. Le Guin","978-0-306-40615-7",1974,"Science fiction",387
"Pride and Prejudice","Jane Austen","978-0-14-143951-8",1813,"Classic",432
"  the quiet streets ","Mara Quill","9780001000100",2019,"Fiction",214
"Loud Roofs","Mara Quill","978-0-00-200029-1",2021,"fiction",198
"Midnight Ledger","Iris Fenwick","978-0-00-300031-3",2016,"Mystery",301
"A Map of Salt","Tomas Arden","9780004000404",2008,"Non-fiction",
"Garden of Small Fires","Noor Haddad","978-0-00-500057-1",,"Poetry",96
"The Lamp at Noon","Le Guin, Ursula K.","978-0-00-600062-4",1999,"Classic",280
"Rivers of Glass","Tomas Arden","",2012,"Non-fiction",352
"THE LONG TABLE","Iris  Fenwick","978-0-00-800085-1",2023,"Fiction ",256
"Paper Moons","Noor Haddad","9780009000911",2005,"Poetry",88
"Notes on Gravity","Elias Moreau","978-0-01-000104-4",2017,"Science fiction",410
"Orchard Logic","Elias Moreau","978-0-01-100112-9",2020,"Non-fiction",175
"The Slow Comet","Priya Raman","978-0-01-200126-4",2014,"science fiction",322
"Ten Winters","Priya Raman","9780013001331",2022,"Fiction",
"Salt and Static","Mara Quill","978-0-01-400145-3",2018,"Mystery",244
loans.csv
"loan_id","isbn","member","loan_date","return_date"
"L001","9780141439518","Hugo Silva","2025-01-14","2025-02-04"
"L002","9780306406157","Ben Okafor","2025-01-16","2025-01-26"
"L003","9780002000291","Dev Patel","2025-01-21","2025-01-22"
"L004","9780005000571","Eva Lindqvist","2025-01-26","2025-02-21"
"L005","978030640615","Ben Okafor","2025-02-19","2025-03-17"
"L006","9780004000404","Hugo Silva","2025-02-28","2025-03-17"
"L007","9780005000571","Grace Liu","2025-03-11","2025-04-04"
"L008","9780001000100","ana ruiz ","2025-03-27","2025-04-06"
"L009","9780001000100","Hugo Silva","2025-03-30","2025-04-30"
"L010","9780306406157","Hugo Silva","2025-04-06","2025-04-27"
"L011","9780010001044","Ben Okafor","2025-04-21","2025-05-27"
"L012","9780013001331","Chloe Martin","2025-04-23","2025-04-20"
"L013","9780005000571","Chloe Martin","2025-05-06","2025-05-27"
"L014","9780009000911","Ana Ruiz","2025-05-07","2025-05-11"
"L015","9780013001331","Ana Ruiz","2025-06-04","2025-07-11"
"L016","9780009000911","Hugo Silva","2025-06-17","2025-07-12"
"L017","9780011001129","Hugo Silva","2025-06-20","2025-07-17"
"L018","9780001000100","Dev Patel","2025-07-01","2025-07-26"
"L019","9780006000624","Ana Ruiz","2025-07-02","2025-07-25"
"L020","9780006000624","Ana Ruiz","2025-02-30","2025-07-15"
"L021","9780011001129","Ben Okafor","2025-07-05","2025-07-21"
"L022","9780008000851","Eva Lindqvist","2025-07-06","2025-07-27"
"L023","9780014001453","Grace Liu","2025-07-08","2025-08-04"
"L024","9780002000291","Grace Liu","2025-07-16","2025-08-08"
"L025","9780014001453","Eva Lindqvist","2025-07-22","2025-08-01"
"L026","9780003000313","Hugo Silva","2025-08-18","2025-08-28"
"L027","9780002000291","Eva Lindqvist","2025-09-12","2025-09-26"
"L028","9780141439518","Ana Ruiz","2025-09-18","2025-09-29"
"L029","9780306406157","Chloe Martin","2025-09-22","2025-10-18"
"L030","9780002000291","Chloe Martin","2025-09-30","2025-10-31"
"L031","9780001000100","Chloe Martin","2025-10-02","2025-10-06"
"L032","9780012001264","Hugo Silva","2025-10-03","2025-10-19"
"L033","9780002000291","","2025-10-11","2025-10-29"
"L034","9780013001331","ana ruiz ","2025-10-14","2025-11-11"
"L035","9780013001331","Ana Ruiz","2025-10-18","2025-11-04"
"L036","9780013001331","Eva Lindqvist","2025-10-20","2025-10-30"
"L037","9780014001453","Chloe Martin","2025-10-30","2025-12-05"
"L038","9780002000291","Grace Liu","2025-11-01","2025-11-08"
"L039","9780306406157","ana ruiz ","2025-11-04","2025-12-01"
"L040","9780006000624","Dev Patel","2025-11-18","2025-12-12"
"L041","9780012001264","Farid Karimi","2025-12-11","2025-12-23"
"L042","9780004000404","ana ruiz ","2025-12-15","2026-01-06"
"L043","9780010001044","Ben Okafor","2025-12-25","2026-01-22"
"L044","9780013001331","Grace Liu","2026-01-03","2026-02-01"
"L045","9780306406157","Farid Karimi","2026-01-05","2026-01-13"
"L046","9780141439518","Ana Ruiz","2026-01-09","2026-02-06"
"L047","9780001000100","Chloe Martin","2026-01-20","2026-02-12"
"L048","9780012001264","Hugo Silva","2026-02-05","2026-03-04"
"L049","9780012001264","Grace Liu","2026-02-10","2026-03-02"
"L050","9780001000100","Grace Liu","2026-02-23","2026-03-14"
"L051","9780010001044","Dev Patel","2026-03-11","2026-03-27"
"L052","9780306406157","Ana Ruiz","2026-03-16","2026-04-05"
"L053","9780004000404","Chloe Martin","2026-03-26","2026-04-19"
"L054","9780013001331","Chloe Martin","2026-04-07",""
"L055","9780306406157","Eva Lindqvist","2026-04-10",""
"L056","9780009000911","Dev Patel","2026-04-20",""
"L057","9780008000851","Dev Patel","2026-04-26",""
"L058","9780001000100","Ana Ruiz","2026-05-03",""
"L059","9780010001044","Ana Ruiz","2026-05-17",""
"L060","9780001000100","Hugo Silva","2026-05-28",""

New here? Read in this order

Then pick topics as you need them and keep the cheat sheet at hand. If you come from another language, read Design Philosophy and Coming from Other Languages first; if you maintain older code, start with What’s New and Migrating Older Code and Idioms and Common Pitfalls.

The map below shows the whole section; the next section lists every page.

mindmap root((R Reference)) Getting started Install and console IDEs Help system Sessions and startup Core language Syntax and assignment Operators and control flow Functions and closures Lazy evaluation Native pipe Vectors and data structures Atomic vectors and NA Subsetting and attributes Factors, matrices and lists Data frames Strings, dates and encodings Functional programming apply family Vectorisation Function factories Object-oriented programming Base types S3 and group generics S4 Reference Classes and R6 S7 Conditions and debugging Conditions Debugging Defensive code Metaprogramming Quoting Evaluation Formulas Data import and export Text files and connections RDS and JSON DBI and HTTP Statistics and graphics Distributions and tests Models Base, grid and lattice ggplot2 Data manipulation ecosystems tidyverse data.table Packages and tooling Namespaces and renv Creating and documenting Testing and linting Scripts and CRAN Performance and interoperability Profiling and memory Parallel computing C, C++, Fortran and Python Quarto, Shiny and plumber Practice and evolution Idioms and pitfalls What is new Cheat sheet

What’s covered

Getting started

Page What it covers

Getting Started

what R is for, installing R on macOS, Windows and Linux, the console, a first session and a first Rscript, the CRAN mirror and what the version number means

Design Philosophy and Coming from Other Languages

the S heritage, vectorisation, length-one vectors, copy-on-modify, lazy evaluation and the object systems, with a mapping from Python, MATLAB, SQL, Java and C#

IDEs and the R Console

the R GUI, the terminal console and its line editor, RStudio, Positron, VS Code, Jupyter and Emacs ESS

IDEs & Tools

the IDEs and editors commonly used for R, with links to RStudio, Positron and the VS Code extension

Getting Help and Documentation

?, help(), help.search(), example(), vignettes, how to read a help page, the manuals, the FAQ and where to ask

Sessions, Workspaces and Startup

the working directory, the workspace and .RData, Renviron and Rprofile files, options(), environment variables and the startup search path

Core language

Page What it covers

Syntax and Lexical Structure

tokens, comments, identifiers and backticks, reserved words, numeric, string and raw-string literals

Assignment, Names and Values

the assignment forms, assign() and get(), super-assignment, copy-on-modify and reference counting

Operators and Precedence

arithmetic, comparison and logical operators, %in%, %||% and %notin%, user-defined %op% operators and the precedence table

Control Flow

if as an expression, switch() with fall-through, for, while, repeat, break and next, and seq_along()

Functions

defining functions, argument matching, defaults, ..., missing(), return values, on.exit(), replacement and infix functions

Scoping, Environments and Closures

environments as objects, lexical scoping, the search path and namespaces, closures and <<-

Lazy Evaluation and Promises

promises, when arguments are forced, force(), default arguments and delayedAssign()

Pipes and the Native Pipe

|> and its _ placeholder, anonymous functions in a pipe and magrittr’s %>%

Vectors and data structures

Page What it covers

Atomic Vectors and Types

the six atomic types, type tests, coercion, recycling and creating vectors

Missing and Special Values

NA and its typed variants, NaN, Inf and NULL, how they propagate and how to remove them

Numbers and Arithmetic

integers and their overflow to NA, IEEE 754 doubles, all.equal(), rounding and integer division

Subsetting and Indexing

the four kinds of index, [, [[, $ and @, drop = FALSE and subassignment

Attributes and Names

attributes(), attr(), structure(), names, dim and class, and which operations keep attributes

Factors

codes and levels, ordered factors, table(), tapply(), cut() and converting factors to numbers

Matrices and Arrays

matrix(), array(), dim and dimnames, cbind(), aperm(), %*% and linear algebra

Lists

recursive vectors, extracting and deleting elements, unlist(), modifyList() and list2DF()

Data Frames

building, inspecting, filtering, sorting, merging, grouping and reshaping data frames

Strings and Regular Expressions

paste(), sprintf(), substr(), strsplit() and the three regular-expression engines

Dates and Times

Date, POSIXct, POSIXlt and difftime, format codes, time zones and date arithmetic

Encodings, Locales and Internationalization

declared encodings, iconv(), UTF-8 on Windows, locales, collation and message translation

Functional programming

Page What it covers

The apply Family and Functionals

lapply(), sapply(), vapply(), mapply(), Map(), apply(), tapply(), Reduce() and Filter()

Vectorisation and Iteration

vectorised operations as loop replacements and when a loop is still the right tool

Function Factories and Higher-Order Functions

functions that return functions, force(), stateful closures, Recall() and Tailcall()

Object-oriented programming

Page What it covers

OOP Overview and Base Types

the SEXPTYPE table, typeof(), class(), inherits() and the object systems built on them

S3 Classes and Generics

constructors, validators and helpers, UseMethod(), NextMethod() and the book class

S3 Group Generics and Operator Overloading

the Math, Ops, Summary and matrixOps groups and double dispatch

S4 Classes and Methods

setClass(), validity, generics with multiple dispatch, show() and virtual classes

Reference Classes and R6

reference semantics with setRefClass() and with R6 classes, inheritance and cloning

The S7 Object System

new_class(), properties, validators, generics and methods in the S7 package

Conditions and debugging

Page What it covers

Conditions and Error Handling

stop(), warning(), message(), tryCatch(), withCallingHandlers(), custom conditions and restarts

Debugging

reading error messages, traceback(), browser(), debug(), trace() and post-mortem debugging

Defensive Programming and Input Validation

stopifnot(), type predicates, match.arg(), %||% and failing early with a clear message

Metaprogramming

Page What it covers

Language Objects and Quoting

symbols, calls and expressions, quote(), substitute(), bquote() and deparse()

Evaluation and Non-Standard Evaluation

eval() and its environments, data masks, with() and subset(), and tidy evaluation in brief

Formulas

the formula language and class, terms, model frames and matrices, contrasts and update()

Data import and export

Page What it covers

Reading and Writing Text Data

read.csv(), write.csv(), readLines(), scan(), fixed-width files and type.convert()

Connections and the File System

every kind of connection, opening modes, compressed files, and files and directories

Serialization: RDS, RData and JSON

saveRDS(), save(), dput(), serialize() and JSON with jsonlite

Databases with DBI

connections, queries, parameterised statements, transactions, backends and dbplyr

HTTP and Web APIs

download.file(), url() and the httr2 package for requests, authentication and errors

Statistics and graphics

Page What it covers

Distributions and Random Numbers

the d, p, q and r functions, set.seed(), the random number generators and sample()

Descriptive Statistics and Tests

summaries, tables, correlations and the classical tests with their htest results

Statistical Models

lm(), glm() and nls(), the extractor generics, diagnostics, anova() and prediction

Base Graphics and Devices

high- and low-level plotting functions, par(), colours and the graphics devices

Grid Graphics and Lattice

viewports, units, grobs and the trellis plots of the lattice package

ggplot2 and the Grammar of Graphics

aesthetics, geoms, stats, scales, facets, themes and ggsave() in ggplot2 4.0

Data manipulation ecosystems

Page What it covers

The tidyverse and dplyr

tidy data, tibbles, tidy evaluation and the dplyr verbs, grouping and joins

tidyr, purrr and stringr

pivoting and rectangling, the purrr map functions and stringr against base R strings

data.table

DT[i, j, by], modification by reference, keys and joins, and fread() and fwrite()

Packages and tooling

Page What it covers

Packages, Libraries and Namespaces

libraries, installing, loading and attaching packages, ::, namespaces and the search path

Reproducible Environments with renv

project libraries, snapshot(), restore(), the lockfile and renv with Docker and CI

Creating Packages

the package layout, DESCRIPTION, NAMESPACE, usethis and devtools, R CMD build and check

Documentation with Rd, roxygen2 and Vignettes

the Rd format, roxygen2 tags and markdown, documenting classes, vignettes and pkgdown

Testing with testthat

test_that(), the expectation families, snapshots, fixtures and mocking

Style, Linting and Static Analysis

the tidyverse style guide, lintr, styler and codetools

Scripts and the Command Line

Rscript, commandArgs(), exit status, standard streams and the shelf report script

Publishing to CRAN

the CRAN Repository Policy, R CMD check --as-cran, the check services and submission

Performance and interoperability

Page What it covers

Performance, Profiling and Benchmarking

system.time(), bench::mark(), Rprof() and profvis, and what to change once you know why code is slow

Memory and Copy Semantics

the SEXP header, copy-on-modify with tracemem(), object.size(), gc() and memory limits

Parallel and Asynchronous Computing

the parallel package, parallel random numbers, future and mirai

Interfacing C, C++ and Fortran

R CMD SHLIB, .Call(), registration, .C() and .Fortran(), and Rcpp

Python Interop with reticulate

choosing an interpreter, importing modules, type conversion and Python errors as R conditions

Reports with Quarto and R Markdown

documents that mix prose and code, chunk options, parameters, output formats and projects

Shiny, plumber and Web APIs

Shiny apps and reactivity, plumber APIs, testing and deployment, the shelf dashboard and API

Practice and evolution

Page What it covers

Idioms and Common Pitfalls

the habits that prevent most R bugs and a catalogue of pitfalls, each with its fix

What’s New and Migrating Older Code

every language change from R 4.0.0 to 4.6.1, the upcoming R-devel changes and how to update older code

Cheat Sheet (PDF)

a one-page, downloadable summary of the whole section

How to cite R

R is free, but its authors ask that it be cited when it is used for data analysis. citation() prints the recommended reference, as text and as a BibTeX entry; the year is the release year of the R version in use (R.version$year). Since R 4.6.0 the citation carries the DOI 10.32614/R.manuals (R NEWS, R FAQ 2.8).

citation()
#> To cite R in publications use:
#>
#>   R Core Team (2026). _R: A Language and Environment for Statistical
#>   Computing_. R Foundation for Statistical Computing, Vienna, Austria.
#>   doi:10.32614/R.manuals <https://doi.org/10.32614/R.manuals>.
#>   <https://www.R-project.org/>.
#>
#> A BibTeX entry for LaTeX users is
#>
#>   @Manual{,
#>     title = {R: A Language and Environment for Statistical Computing},
#>     author = {{R Core Team}},
#>     organization = {R Foundation for Statistical Computing},
#>     address = {Vienna, Austria},
#>     year = {2026},
#>     doi = {10.32614/R.manuals},
#>     url = {https://www.R-project.org/},
#>   }
#>
#> We have invested a lot of time and effort in creating R, please cite it
#> when using it for data analysis. See also ‘citation("pkgname")’ for
#> citing R packages.

Packages are cited the same way, with the package name as the argument. citation("pkg") returns a bibentry object, built from the package’s inst/CITATION file when it has one and from its DESCRIPTION file otherwise, and format() renders it in a chosen style. Cite the package version you used too, which packageVersion() reports:

citation("ggplot2") |> format(style = "text") |> writeLines()
#> Wickham H (2016). _ggplot2: Elegant Graphics for Data Analysis_.
#> Springer-Verlag New York. ISBN 978-3-319-24277-4.
#> <https://ggplot2.tidyverse.org>.
packageVersion("ggplot2")
#> [1] ‘4.0.3’

Creating Packages shows how a package declares its own citation, and the R FAQ entry gives the BibTeX form to paste into a bibliography.

How this section relates to the others

Some related work is planned in other issues of this repository and is not linked yet: a programming-languages comparison (#196), a Data Science section on NumPy, pandas and scikit-learn (#244), an AI and machine-learning section (#245) and a MATLAB reference (#248). If a Data Science section is added, the statistics, graphics and tidyverse pages of this section are the natural R counterpart.

Bibliography

Every source cited by the pages of this section is listed here, grouped by origin, and each one is cited again on the page that uses it (in its == References section, in the Source: line after an example, or in the text). The lists cover every external link on this page, the 71 topic pages and the cheat sheet, wherever it appears (== References sections, Source: lines, tables and prose), de-duplicated by document, so a manual or a help page appears once however many pages cite it; the section anchors used inside the manuals are not repeated here. Every link was checked on 2026-10-22; the ISO site answers scripted requests with HTTP 403, so its ISO 8601 page could not be checked automatically.

Official R Project documentation and resources

Official package documentation

Documentation of add-on packages, labelled as package documentation, not R Project documentation. Each package is listed with its own site (pkgdown, project site or CRAN page) and every reference page, article or vignette used; the version each page was checked against is stated in that page’s introduction.

Package development, testing and tooling
Data manipulation, import and graphics
Databases, web and data formats
Performance and parallelism
Reports, apps and APIs
Command-line scripts
Other projects' official documentation, cited for comparison or as system dependencies

Community references

Community references, labelled as such: free online books by package authors, style guides and community tools. The books were consulted for concept coverage only; they are never the primary source of an example, no text, code listing or figure was copied from them, and on any discrepancy the official R or package documentation wins. Advanced R predates S7, the native pipe, the \(x) shorthand and the R 4.2 and 4.3 errors for conditions of length greater than one, and the pages that consult it say so.