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