Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open a script file in RStudio using an R command?

Tags:

r

rstudio

I have a simple script file called test.R. It's saved in the working directory. When I go to File > Open > test.R, it opens the file in the editor (without executing the code, which is what I want).

How do I do this by typing a command in the console window? To be clear, I just want to open (not execute) the file.

like image 892
user3654852 Avatar asked May 20 '14 03:05

user3654852


People also ask

How do I load a script into RStudio?

The easiest way to do that is from within RStudio. Open a simple text file called an R script file by choosing the New File icon at the top-left, then choose R Script. RStudio can copy R commands from this text file and insert them into the R console as if you were manually entering commands yourself directly into R.

How do I run an entire Rscript in RStudio?

In addition, in Rstudio you can run the entire script by pressing Ctrl + Shift + Enter without selecting any code. In addition, there is a shortcut to source the current script file ( Ctrl + Shift + s ), which runs the script without echoing each line.

How do I run an R file in R terminal?

If R has been installed properly, simply entering R on the command line of a terminal should start the program. In Windows, the program is typically specified as the action performed when clicking on an icon. You can also use this method on a *NIX system that has a window manager such as KDE.


2 Answers

You are looking for file.edit

file.edit('test.R') 

should open the file in an editor (if you are in RStudio, this should default to RStudio)

like image 145
mnel Avatar answered Oct 24 '22 18:10

mnel


It appears that if you are using RStudio then another option is to use rstudioapi::navigateToFile("test.R")

like image 20
dpritch Avatar answered Oct 24 '22 19:10

dpritch