How to Run a Single Line in RStudio

Viewed 6817

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?

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".

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

Related