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

user3654852 picture user3654852 · May 20, 2014 · Viewed 42.4k times · Source

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.

Answer

mnel picture mnel · May 20, 2014

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)