R Base Functions Cheat Sheet: 100 Functions You Actually Need
These are the 100 base R functions that working data analysts and statisticians use most often. No packages required — everything here ships with R out of the box.
R has over 1,200 base functions, but most programmers rely on the same 100 day after day. This cheat sheet distills those essentials, organized by what you're trying to do. Every function includes a signature, a one-line description, and a runnable example.
Object Inspection (10 Functions)
These are the first functions you reach for when exploring unfamiliar data.
# Apply family showcase
cat("Column means:\n")
print(round(apply(mtcars[,1:4], 2, mean), 1))
cat("\nMPG by cylinder:\n")
print(round(tapply(mtcars$mpg, mtcars$cyl, mean), 1))
IO & File System (10 Functions)
#
Function
What It Does
Example
81
read.csv(file)
Read CSV
read.csv("data.csv")
82
write.csv(x, file)
Write CSV
write.csv(df, "out.csv")
83
readRDS(file)
Read R object
readRDS("model.rds")
84
saveRDS(object, file)
Save R object
saveRDS(fit, "model.rds")
85
readLines(con, n)
Read text lines
readLines("log.txt", 10)
86
writeLines(text, con)
Write text lines
writeLines(c("a","b"), "out.txt")
87
cat(...)
Print to console
cat("value:", 42, "\n")
88
print(x)
Print object
print(head(mtcars))
89
getwd()
Working directory
getwd()
90
file.exists(x)
File exists?
file.exists("data.csv")
Control Flow & Error Handling (10 Functions)
#
Function
What It Does
Example
91
if/else
Conditional
if (x > 0) "pos" else "neg"
92
ifelse(test, yes, no)
Vectorized conditional
ifelse(1:5 > 3, "hi", "lo")
93
switch(expr, ...)
Multi-branch
switch("b", a=1, b=2, c=3)
94
for(var in seq)
Loop
for (i in 1:5) cat(i)
95
while(cond)
While loop
while(x < 10) x <- x + 1
96
tryCatch(expr, ...)
Error handling
tryCatch(log(-1), warning=function(w) NA)
97
try(expr)
Try without stopping
try(log("a"), silent = TRUE)
98
stop(msg)
Throw error
stop("x must be positive")
99
warning(msg)
Issue warning
warning("Unusual value")
100
message(msg)
Print message
message("Processing done")
# Error handling in practice
safe_log <- function(x) {
tryCatch(
log(x),
warning = function(w) { message("Warning: ", w$message); NA },
error = function(e) { message("Error: ", e$message); NA }
)
}
cat("log(10):", safe_log(10), "\n")
cat("log(-1):", safe_log(-1), "\n")
cat("log('a'):", safe_log("a"), "\n")
Summary: The Top 20 You'll Use Daily
Rank
Function
Category
1
c()
Creating
2
str()
Inspection
3
head()
Inspection
4
summary()
Statistics
5
mean()
Statistics
6
length()
Inspection
7
names()
Inspection
8
paste0()
Strings
9
sapply()
Apply
10
which()
Searching
11
cat()
IO
12
read.csv()
IO
13
class()
Inspection
14
ifelse()
Control
15
unique()
Manipulation
16
subset()
Subsetting
17
gsub()
Strings
18
round()
Math
19
sort()
Sorting
20
tryCatch()
Error handling
FAQ
What counts as "base R"? Base R means functions available without loading any packages. These come from the base, utils, stats, grDevices, and graphics packages that ship with every R installation.
Should I learn base R or tidyverse first? Learn base R first. Understanding c(), [, $, apply(), and the type system makes tidyverse code easier to debug and understand. Tidyverse is built on top of base R, not a replacement.
How can I check all arguments a function accepts? Use args(function_name) or ?function_name. For example, args(read.csv) shows all parameters, and ?read.csv opens the full help page with descriptions.
What's Next
R Cheat Sheet — Extended 200-function reference organized by category