R Studio Version 1.1.456 Verson; R version 3.5.1 on Mac basic question about editing codes in R console

I am new to R Studio. I am seeing when we hit enter in R console it executes the code. How do we write codes directly in console? For example when I write a sequence of codes and how to go to new line without hitting "enter" which is basically executing the code.

Are we supposed to write the code in R script editor and saved as an R file. Please bear with me that this is a basic question. Thank you.

Yes, you got it right. Usually you would write any non-trivial amount of code in code editor and then execute either the whole thing or line by line. Normally, at least for me, console is just to try out something very quickly and pretty much everything else goes into code editor.

There are two ways to execute line-by-line:

  1. Ctrl + Enter - this will execute the line and move to the next line, so you can execute multiple steps in a row, if you need.
  2. Shift + Enter - this will execute the line and stay at the same line, so you can execute some piece of code multiple times in a row.

Finally, you might want to get a more thorough introduction to R in general with, for example, this online book - R for Data Science.

1 Like

Thank you. I very much appreciate it.