Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Run a Single Line in RStudio

Tags:

r

rstudio

I am used to using the standard R GUI but I'm trying to make the switch to RStudio. However, it's driving me nuts that I can't figure out how to run a single line with a keyboard shortcut. For instance, if I have the two lines,

c <- a +
     b

I would like to press ^R to run the first line and then have to press ^R again to run the second line to complete the assignment. This is the default setting in the standard R GUI. Unfortunately, RStudio only seems to want to execute a statement to it's completion. Is there any way around this?

like image 945
jjet Avatar asked Oct 26 '25 08:10

jjet


2 Answers

If you want this to be the default behavior, go to "Tools -> Global Options -> Code -> Editing" and uncheck the box "Execute all lines in a statement" under "Execution".

like image 76
Alexey Shiklomanov Avatar answered Oct 27 '25 22:10

Alexey Shiklomanov


Select the first line (by clicking on it three times), then Ctrl-Enter will run the selection, not the statement.

like image 32
user2554330 Avatar answered Oct 27 '25 23:10

user2554330