R Output
Output is the text a script shows when it runs. R has two commands for output, print and cat.
print adds a prefix and quotes
print shows text with quotes and a prefix. A number prints with the prefix and no quotes.
print("hello")
print(42)cat prints plain text
cat shows plain text with no prefix. Each cat line adds one plain line.
cat("Hello there\n")
cat("Plain and simple\n")Bare values print on their own
A bare number prints on its own line. A bare calculation prints its result.
42
3 + 4Example
print("Report ready")
cat("Rows", " counted\n", sep = "")Key points
- print shows a value with a [1] prefix at the start of the line.
- The [1] prefix gives the position of the first value on the line.
- print puts quotes around text values.
- cat prints plain text with no prefix and no quotes.
- cat joins its parts with a space by default.
- An empty sep joins the parts with no gap at all.
- A bare value on its own line prints itself.
In this example print shows the first line with a prefix and quotes. The cat line joins its two parts with an empty sep. The result is one plain line with no prefix.
Try it Yourself
Edit the code, then press Run.
Running is simulated ยท rdrr.io R Snippets
Exercise
What does the [1] prefix mean?