.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.

What opens 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.

Windows

  • RStudio
  • VS Code
  • any text editor

macOS

  • RStudio
  • VS Code
  • any text editor

Linux

  • RStudio
  • VS Code
  • Rscript

Open a .r file step by step

  1. Confirm the file really is a .r. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
  2. On Windows, open it with RStudio or VS Code.
  3. On Mac, use RStudio or VS Code.
  4. On Linux, try RStudio or VS Code.
  5. Still stuck? Search for a dedicated R viewer rather than a generic one.

Why can't I open my .r file?

Almost always because no installed app understands R. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.

The other possibility is that the file is not really a .r at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.

R has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.

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. How sources are ranked and what is deliberately left out is set out in the methodology.