What Is R Markdown? Reports, Code and Output in One File
September 11, 2026 · 9 min read
What Is R Markdown? Reports, Code, and Output in One File
If you're asking what is R Markdown, here's the short answer. It's a file format (.Rmd) that mixes Markdown prose with runnable R code, so one document produces a finished report with the results already in it. Press Knit and you get HTML, PDF, or Word. This guide explains the pipeline, gives you a copy-ready first document, and compares it with Quarto and Jupyter.
The Short Definition
It's an authoring format from the rmarkdown package, maintained by Yihui Xie and at version 2.32 on CRAN as of 1 September 2026. An .Rmd file has three parts: a YAML header describing the output, Markdown text, and code chunks.
When you render it, the code runs, its output (numbers, tables, plots) is inserted, and the whole thing is converted to the format you asked for. The result is a report that can never disagree with its own analysis, because the analysis produced it.
The Markdown half is ordinary Markdown. If # headings and **bold** are new to you, our plain-English Markdown introduction is the place to start. Everything R-specific sits inside the chunks and the header.
How Does the R Markdown Pipeline Work?
This is the single idea that makes everything else click. The official How It Works page describes two stages, and it's worth holding them separately in your head.
- knitr reads the
.Rmd, executes every code chunk in a fresh R session, and writes a plain.mdfile that contains your text plus the code's output. - Pandoc converts that
.mdfile into HTML, PDF (via LaTeX), Word, or slides.
So .Rmd becomes .md becomes .html. RStudio hides both steps behind the Knit button, and rmarkdown::render("report.Rmd") runs them from the console. Two consequences follow. First, "markdown in R" is really Pandoc's Markdown, so features like footnotes and citations come from Pandoc, not from R. Second, R Markdown isn't slower than R: the code takes exactly as long as it would in a script, and the conversion adds a second or two.
The format vs RStudio is a common confusion. RStudio is the editor; the .Rmd file is the format. You can write .Rmd files in VS Code or any text editor and render them with one R command.
Your First .Rmd Document
Here's a complete .Rmd file. Copy it, save it as first-report.Rmd, and knit it.
---
title: "Fuel Economy Summary"
author: "Your Name"
date: "2026-09-11"
output: html_document
---
## Data
The built-in `mtcars` data set has `r nrow(mtcars)` cars and `r ncol(mtcars)` variables.
```{r summary}
summary(mtcars$mpg)
```
## Plot
```{r plot, echo=FALSE, fig.width=6}
plot(mtcars$wt, mtcars$mpg, xlab = "Weight (1000 lbs)", ylab = "Miles per gallon")
```
Heavier cars use more fuel; the relationship is roughly linear.
Three things to notice. The chunk header {r summary} names the chunk and can carry options: echo=FALSE hides the code but keeps its output, fig.width=6 sizes the plot in inches. The inline code `r nrow(mtcars)` runs inside a sentence, so the count is always right. And the output: key in the header is the only line you change to get a PDF (pdf_document) or Word file (word_document).
For the full list of chunk options, output formats, and the YAML keys, the R Markdown cheat sheet is the syntax reference; this post stays on the explainer side. The header on its own has enough options to fill a post, which is why we wrote a separate YAML header guide.
How to Use R Markdown in RStudio
In RStudio, run install.packages("rmarkdown") once. Then go to File > New File > R Markdown, pick a title and a default output format, and RStudio opens a template with three example chunks. Replace the template with the document above.
Click Knit (Ctrl+Shift+K on Windows and Linux, Cmd+Shift+K on a Mac). RStudio runs the pipeline and opens the finished HTML in its viewer, next to a first-report.html file on disk.
PDF needs one extra step, because Pandoc hands the job to LaTeX. The lightweight route is TinyTeX:
install.packages("tinytex")
tinytex::install_tinytex()
After that, change output: html_document to output: pdf_document and knit again. Missing LaTeX packages install themselves on first use. Word output needs nothing extra; Pandoc writes .docx natively.
You don't need RStudio, either. Install the R extension by REditorSupport, install the languageserver package in R, and the extension gives you syntax highlighting, chunk execution, and a knit command for .Rmd files. You still need R and the rmarkdown package installed; VS Code is just the editor. Rendering runs the same rmarkdown::render() call RStudio uses, so output is identical.
Try the Markdown Half in the Editor
Everything outside the chunks is standard Markdown. It's also the part most beginners get wrong first: headings need a space after the #, and lists need a blank line before them. The editor below holds the prose from the sample document with the chunk output written in by hand. That's what knitr's .md stage looks like before Pandoc styles it. The chunk and its output appear as a plain fenced code block here because the editor is a Markdown renderer, not an R session.
If your rendered report looks wrong, paste the text portion into the editor first. When it renders correctly there, the problem is in a chunk or the header, not the Markdown.
Why Is R Markdown Useful Compared to an R Script or a Notebook?
An R script produces results you then copy into a document by hand. Change the data and the document is stale until someone remembers to update it. The .Rmd approach removes that step: the numbers in the text are computed when the file renders, and the plot is whatever the code drew today.
That makes it the right tool for anything you'll regenerate: weekly reports, homework, papers, dashboards, package vignettes, and books (the bookdown package builds on it). It's the wrong tool for long-running pipelines and for functions you reuse across projects. Keep those in .R files and call them from a short .Rmd that only does the reporting. We prefer that split over one giant notebook because the script stays testable.
Is it like a Jupyter Notebook? Yes in purpose, no in mechanics. Both mix prose, code, and output. The differences matter when you pick one:
| R Markdown | Jupyter Notebook | |
|---|---|---|
| File | Plain text .Rmd | JSON .ipynb with outputs stored inside |
| Runs | Top to bottom in a fresh session on every render | Cells in any order, state kept in a kernel |
| Version control | Clean diffs | Diffs full of output blobs |
| Output | HTML, PDF, Word, slides via Pandoc | HTML and PDF via nbconvert |
| Languages | R first; Python, SQL, bash via knitr engines | Any kernel, Python first |
The fresh-session rule is the big one. An .Rmd that knits is reproducible by construction; a notebook can depend on a cell you ran an hour ago and deleted. For the Markdown syntax inside notebook cells, see the Jupyter Markdown cheat sheet.
R Markdown or Quarto in 2026?
Posit's newer system, Quarto, uses .qmd files with nearly identical syntax and works with R, Python, and Julia. The official Quarto FAQ on the subject is direct about it: "R Markdown is not going away." It will keep getting bug fixes and small improvements, but no major new features are planned. Quarto renders most .Rmd files unmodified.
Our advice: if you're joining a team or course that uses .Rmd files, learn it; the 2.32 release in September 2026 shows it's still maintained. If you're starting fresh and you'll ever mix Python into your reports, start with Quarto. Everything in this post transfers, and our Quarto Markdown guide covers the syntax that's Quarto-only.
One limitation applies to both: rendering to PDF depends on LaTeX, and LaTeX errors are cryptic. When a PDF knit fails, switch to html_document to confirm the R code is fine, then debug the LaTeX side separately.
R Markdown FAQ
So, what is R Markdown? A plain text file where Markdown prose, R code, and the code's output live together and render to HTML, PDF, or Word in one click. Start with the sample document above, keep the cheat sheet nearby, and when the Markdown side misbehaves, paste it into the editor to see exactly what Pandoc will receive.