R Cheat Sheet
|
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. |
A single-page, colour-coded summary of R, written against R 4.6.1 (released 2026-06-24) and checked on 2026-10-22, when R 4.6.2 was at release-candidate stage and scheduled for 2026-10-29 — the tool map (R, Rscript, R CMD build/check/INSTALL, RStudio and Positron), getting help and the startup files, syntax (<-, <<-, backticks, raw strings, |> with the _ placeholder, \(x)), the six atomic types with their literals, the coercion order and the special values (NA, NULL, NaN, Inf), vectors and recycling with %in%, %notin% and %||%, a subsetting grid for [, [[, $ and @, factors, matrices, lists and data frames, control flow, functions (argument matching, ..., match.arg(), on.exit(), closures, replacement functions), environments and lazy evaluation, the apply family, strings, regular expressions and dates, S3, S4, Reference Classes, R6 and S7 side by side, conditions and debugging, metaprogramming and formulas, I/O with files, connections, RDS, JSON, DBI and httr2, distributions, tests, models and graphics, tidyverse and data.table one-liners, packages, renv, roxygen2 and testthat, performance and parallelism, and a strip of what changed from R 4.0 to R 4.6 — handy for quick memorization or as a downloadable PDF desk reference.
For the full explanation, every option, and additional examples, see the dedicated pages:
Start here — R Reference.
Getting started — Getting Started, Design Philosophy and Coming from Other Languages, IDEs and the R Console, Getting Help and Documentation and Sessions, Workspaces and Startup.
Core language — Syntax and Lexical Structure, Assignment, Names and Values, Operators and Precedence, Control Flow, Functions, Scoping, Environments and Closures, Lazy Evaluation and Promises and Pipes and the Native Pipe.
Vectors and data structures — Atomic Vectors and Types, Missing and Special Values, Numbers and Arithmetic, Subsetting and Indexing, Attributes and Names, Factors, Matrices and Arrays, Lists, Data Frames, Strings and Regular Expressions, Dates and Times and Encodings, Locales and Internationalization.
Functional programming — The apply Family and Functionals, Vectorisation and Iteration and Function Factories and Higher-Order Functions.
Object-oriented programming — OOP Overview and Base Types, S3 Classes and Generics, S3 Group Generics and Operator Overloading, S4 Classes and Methods, Reference Classes and R6 and The S7 Object System.
Conditions and debugging — Conditions and Error Handling, Debugging and Defensive Programming and Input Validation.
Metaprogramming — Language Objects and Quoting, Evaluation and Non-Standard Evaluation and Formulas.
Data import and export — Reading and Writing Text Data, Connections and the File System, Serialization: RDS, RData and JSON, Databases with DBI and HTTP and Web APIs.
Statistics and graphics — Distributions and Random Numbers, Descriptive Statistics and Tests, Statistical Models, Base Graphics and Devices, Grid Graphics and Lattice and ggplot2 and the Grammar of Graphics.
Data manipulation ecosystems — The tidyverse and dplyr, tidyr, purrr and stringr and data.table.
Packages and tooling — Packages, Libraries and Namespaces, Reproducible Environments with renv, Creating Packages, Documentation with Rd, roxygen2 and Vignettes, Testing with testthat, Style, Linting and Static Analysis, Scripts and the Command Line and Publishing to CRAN.
Performance and interoperability — Performance, Profiling and Benchmarking, Memory and Copy Semantics, Parallel and Asynchronous Computing, Interfacing C, C++ and Fortran, Python Interop with reticulate, Reports with Quarto and R Markdown and Shiny, plumber and Web APIs.
Practice and evolution — Idioms and Common Pitfalls and What’s New and Migrating Older Code.
References
The PDF summarizes the official documentation; each source is cited in full on the page listed above that covers it, and in the section bibliography.