R Get Started
A script is a text file whose lines run in order from the top. R runs each line once and then moves to the next one.
One line runs
This script holds one print line. The line runs and shows its text.
print("The script starts")Lines run in order
The top line runs first. The next line runs after it.
print("First the top line")
print("Then the second line")Three lines in order
Three print lines run from the top down. Each line adds one line to the output.
print("Step one")
print("Step two")
print("Step three")Example
print("Shopping list")
print("Milk and eggs")
print("List complete")Key points
- This course names the script file main.R.
- The run command is Rscript main.R.
- R needs no main function at the top of a script.
- The first line runs first and the last line runs last.
- Each print call adds one line to the output.
In this example the three lines run from the top down. The output lines appear in the same order as the script lines.
Try it Yourself
Edit the code, then press Run.
Running is simulated ยท rdrr.io R Snippets
Exercise
What command runs the script main.R?