While R Studio is a fantastic tool to get started learning R, it is only an interface to the R console. It is important to be friendly with running R programs directly through the command prompt or terminal because you might not always have access to a graphical interface if you are running R functions on a server.

If R is installed properly, you can simply open the R console by typing ‘R’ on the terminal and pressing Enter.

When you start R, the first thing you will be seeing is the R console with the default “>” prompt. We can start typing commands directly at the prompt and hit return to run it.

For an instance, try writing the following commands on the R prompt

> n <- c(2, 3, 5, 10, 14)
> mean(n)
[1] 6.8

As you can see, each command is executed as soon as you press the enter key and if there is any output(the mean in the above example), then it will be displayed.

If the command is incomplete when you hit enter, the prompt changes to “+” and continues to take input till the command is syntactically complete.

Else, we can execute R commands stored in an external file using the function source() as follows.

> source("example.R ")
To exit the command prompt we can call the q() function (as in quit).
> q()

To learn more on this, opt for r online course.