AlainD
AlainD

Reputation: 6597

RStudio console stuck - how to reset?

Using Version 0.98.11013. Say I'm testing the following code in my script:

for (num in 1:5)
{
    # Print numbers from 1 to the loop variable
    print(1:num)
}

As I step over each line (using CTRL+R), I get the following output in the Console:

> for (num in 1:5)
+ {
+ # Print numbers from 1 to the loop variable
+ print(1:num)
+ }
[1] 1
[1] 1 2
[1] 1 2 3
[1] 1 2 3 4
[1] 1 2 3 4 5
> 

Now, say I've made an error in my code and forgotten the closing brace }:

for (num in 1:5)
{
    # Print numbers from 1 to the loop variable
    print(1:num)

randomArray <- c(1:10)
# ...and the next line of the R script

Now the Console shows a + symbol for every line because it is looking for a closing brace. Someone new to R or RStudio may not be aware of this. Nothing I do gets output working again except closing and re-opening RStudio.

Is there a way to force the RStudio Console (or is it the R interpreter?) to "reset"?

Upvotes: 2

Views: 41499

Answers (3)

sparkyjump
sparkyjump

Reputation: 117

Ctrl + l works in R console (Mac)

I recently for the first time had line numbers in the console where Ctrl + l did not clear everything, but ESC followed by Ctrl + l did.

Upvotes: 3

989
989

Reputation: 12937

Apart from Esc key that works in both RStudio and R console,

  • Ctrl + z does work in R console (Windows)
  • Ctrl + c does work in R console (Linux)(thanks to @Spacedman for pointing out the key for Linux)

In general, RStudio → Tools → Keyboard Shortcuts Help might come handy. Or just press Alt + Shift + k

Upvotes: 3

xtluo
xtluo

Reputation: 2121

Try click in the Console and then press the keyboard button ESC.

Upvotes: 26

Related Questions