.r

What is a .r file?

R Source File · Code and data · R Core Team · 1993

A .r file is R source code, the language of statistics and data analysis. Researchers and data scientists use it to clean data, run statistical models and produce charts.

Category
Code and data
Type
Plain text
Is a .r file safe to open? Caution. An .r file is a script that runs when executed. Review unfamiliar scripts before running them.

What is a .r file used for?

R is built for data: it has statistics, data frames and plotting at its core, plus thousands of packages for specialised analysis. Scripts are run with Rscript or inside RStudio.

The files are plain text and open in any editor. A related .rdata or .rds file stores saved R objects rather than code.

How to open a .r file

The .r format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .r file.

Windows

  • RStudio
  • VS Code
  • any text editor

macOS

  • RStudio
  • VS Code
  • any text editor

Linux

  • RStudio
  • VS Code
  • Rscript

.r file signature (magic bytes)

Programs recognise a .r file by the bytes at the start of the file, not by its name. These are the signatures for R.

Hex signatureOffsetNote
(no fixed signature)0plain text; no fixed magic bytes

See the full magic-numbers reference for every format.

Frequently asked questions

What is a .r file?

A .r file is R source code, the language of statistics and data analysis. Researchers and data scientists use it to clean data, run statistical models and produce charts.

How do I run an .r file?

Open it in RStudio and run it, or from a terminal run Rscript file.r with R installed.

What is the difference between .r and .rdata?

An .r (or .R) file is R source code. An .rdata or .rds file stores saved R data objects, not code, to reload later.

How do I open an .r file to read it?

Any text editor shows the source. RStudio adds a console, plots and full R tooling.

Related formats

Sources

Details on this page were checked against authoritative references: