An R file is a script written in the R programming language.
These files end with an .R extension. For example, an R script might be saved as my_script.R.
These files are typically used within RStudio, an interactive environment where you can work with R code.
The following example shows how to open an R script in RStudio in practice.
Example: Open R File in RStudio
Suppose I have an R script called my_script.R saved on my Desktop.
To open this file in RStudio, I can click File and then click Open File:
I can then navigate to Desktop and double click on the my_script.R file:
The R script will automatically open in RStudio:
You can now edit the R script or run the code that already exists within it.
It’s also worth noting that if the current working directory already contains the R script you’re interested in, you can open the R script by typing the following code in RStudio:
#open my_script.R file in RStudio file.edit('my_script.R')
The R script will automatically open in RStudio.
The following tutorials explain how to use other common functions in R: