What is the R file format?
.r files (conventionally written as .R with an uppercase letter) contain source code for the R statistical programming language, created by Ross Ihaka and Robert Gentleman at the University of Auckland in 1993. R is the dominant language for statistical computing, bioinformatics, and data science in academic and scientific research.
An .R script is plain UTF-8 text with no mandatory structure - statements execute top-to-bottom, or define functions for later loading via source(). Typical scripts begin with library() calls to load packages, use the <- operator for assignment, apply tidyverse or base-R data manipulation, fit statistical models with functions such as lm() or glm(), and generate visualizations through ggplot2 or base graphics. Comments are prefixed with #. Scripts run from the command line with Rscript script.R or interactively inside RStudio. On Unix systems the shebang #!/usr/bin/env Rscript allows direct execution.
A practical annoyance: on case-sensitive file systems (Linux, macOS) .R and .r are distinct files. GitHub Linguist historically misidentified .r as REBOL rather than R; REBOL's community has since shifted toward .reb and .r3 extensions to reduce ambiguity. Related formats include R Markdown (.rmd) for literate programming and RData (.rdata) for serialized R objects.
Security & safety
RISK: MEDIUMR scripts are interpreted code - executing an untrusted .R file can perform arbitrary file system operations, make network requests, and install packages. Before running a script from an unknown source, open it in a text editor to review its contents. R code can call system() and shell() to execute OS commands. Treat unknown .R files like any other executable script.
Format details
in a nutshell- REBOL Script - REBOL (Relative Expression Based Object Language) historically used .r; community now prefers .reb / .r3 to avoid confusion with R statistical scripts.
Programs that open R files
Technical details
deep spec| Text encoding | UTF-8 (recommended and default in modern R); ASCII or system locale accepted by older versions |
| Comment syntax | `#` prefix for line and inline comments; no block comment syntax in base R |
| Assignment operator | `<-` (canonical R style); `=` is valid but conventionally reserved for function argument passing |
| Case sensitivity | On case-sensitive file systems (Linux, macOS) `.R` and `.r` are distinct; GitHub Linguist may misclassify `.r` as REBOL |
| Execution methods | `Rscript script.R` from the command line; `source("script.R")` within an R session; interactive REPL in RStudio |
| Shebang support | `#!/usr/bin/env Rscript` on the first line enables direct Unix execution when the file is marked executable |
| Package system | `library(pkgname)` imports packages; over 20,000 packages on CRAN; Bioconductor for genomics workflows |
| No mandatory structure | No required `main()` function or module declaration; execution proceeds top-to-bottom |
| Typical file size | Under 100 KB for most analytical scripts; can reach several MB if large data vectors are embedded as literals |
| Dominant IDE | RStudio (Posit) - provides syntax highlighting, integrated REPL, plot viewer, and package management for `.R` files |
| Ecosystem roles | Statistical modeling (`lm()`, `glm()`), data wrangling (dplyr, tidyr), visualization (`ggplot2`), bioinformatics (Bioconductor) |
| Reproducibility practice | `set.seed()` for stochastic reproducibility; `sessionInfo()` to record the runtime environment for published analyses |
| Released | 1993 (R language); .R extension used since R's public availability (~1995) |
| Latest version | R 4.4.x (2024); language and .R format unchanged in structure |
| Open standard | Yes · royalty-free |
| Specification | www.r-project.org |
R conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about R files.