R

R is a language built by statisticians for statistics — and it shows, in both the good ways and the strange ones. Vectors are the default unit of computation, missing values (NA) are first-class citizens, model formulas (y ~ x1 + x2) are syntax, and the newest methods from academic statistics land in R packages years before anywhere else.

While Python won general-purpose data science, R remains dominant where rigorous statistics is the job: biostatistics and clinical trials (pharma runs on R), epidemiology, ecology, econometrics, and any team whose deliverable is analysis rather than software. Its visualization (ggplot2) and literate-reporting (Quarto) stories are still arguably the best in the business.

TL;DR

Quick Example

A complete analysis in tidyverse style — wrangle, summarize, model, plot:

Nothing here is pseudocode — this density of analysis-per-line is R's core value proposition.

Core Concepts

Vectors and Vectorization

Everything is a vector; scalars are length-1 vectors. Operations broadcast element-wise:

NA (missing) propagates deliberately — mean(c(1, 2, NA)) is NA until you say na.rm = TRUE. Annoying until you've been saved by it: R refuses to silently pretend missing data isn't missing.

Data Frames and dplyr

The tidyverse verbs read like the analysis you'd describe aloud:

The same pipeline vocabulary as Pandas — many find dplyr's version more readable, and dbplyr even compiles these pipelines to SQL against a live database. For big data on one machine, data.table (blazing fast) and duckdb's R bindings extend the same workflows past RAM comfort.

ggplot2: The Grammar of Graphics

Plots compose from layers — data, aesthetic mappings, geometries, scales, facets:

Because every element is a composable layer, the leap from "quick look" to "publication figure" is additive, not a rewrite. The grammar was so successful it's been reimplemented everywhere (plotnine in Python, gadfly, Vega-Lite's lineage).

Statistics as a First-Class Citizen

The formula interface makes model specification declarative:

Beyond the classics, R is where new methods appear first: the reference implementations for most modern statistical techniques are CRAN packages written by the method's authors. broom tidies any model into data frames; marginaleffects/emmeans handle the interpretation layer.

Reproducible Reporting

Quarto (R Markdown's successor) interleaves prose, code, and output into HTML/PDF/Word reports, slides, dashboards, and books — re-rendered from source so numbers never drift from the analysis that produced them. Add Shiny for interactive web apps written purely in R, and renv for per-project package lockfiles, and you have R's real deliverable: not programs, but reproducible analyses people can read.

R vs Python for Data Work

The grown-up answer is "both, by task": Python for pipelines, ML systems, and anything deployed; R for statistical analysis, visualization, and reports. Quarto happily runs both in one document, and many data teams do exactly that.

Common Mistakes

Writing Loops Where Vectors Work

Ignoring NA Semantics

sum(x) returning NA is R telling you data is missing. Investigate before reflexively na.rm = TRUE-ing it away — silent NA-dropping is how analyses lie.

stringsAsFactors Trauma and Type Surprises

Base R has historical sharp edges (factors, partial matching, sapply's type instability). The tidyverse (and vroom/readr for IO) exists partly to sand these off — new code should start there, not in 2005-style base R.

No Project Discipline

Absolute paths (setwd("C:/Users/me/...")) and no dependency locking make analyses unreproducible in a month. Use RStudio/Positron projects, the here package for paths, and renv for packages.

Deploying R Like It's a Backend Language

An R script cron-jobbed into production without engineers who know R becomes an orphaned liability. Either productionize properly (Plumber APIs, containerized, owned) or hand the model to the Python service layer.

FAQ

Should I learn R or Python first?

Default: Python — broader market, one language for analysis and engineering. Learn R first if your field runs on it (biostatistics, epidemiology, pharma, ecology, academic social science) or your team already does. Second-language R after Python is a quick pickup, and the reverse works too.

Is R still relevant?

Yes, in its stronghold: regulated-industry statistics (FDA submissions increasingly accept R), academia, and any shop whose product is analysis. It has ceded general data-science mindshare to Python while its core toolchain (tidyverse, Quarto, Shiny for Python and R) keeps improving.

What's the tidyverse vs base R debate?

Base R is stable and dependency-free; the tidyverse is a coherent, readable dialect that most modern instruction uses. Practical answer: learn tidyverse idioms for analysis, absorb enough base R to read older code and write packages. data.table is the third dialect — terse and extremely fast — worth knowing at scale.

Can R handle big data?

Bigger than its reputation: data.table and DuckDB handle tens of GB on one machine comfortably, dbplyr pushes computation into warehouses, and sparklyr drives Spark from R. Truly distributed pipelines, though, are usually built in the Spark/Python world and consumed from R.

What IDE do R users use?

RStudio remains the standard (its maker, Posit, stewards much of the ecosystem); Positron is its next-generation successor supporting R and Python side by side; VS Code with the R extension is a solid alternative.

Related Topics

References