Every R script can print output with print() or cat(). Unlike Python print(), cat() concatenates strings without adding quotes or newlines unless you include \n.
Minimal program
print("Hello, World")
cat("Hello, World\n")
print() shows the value with default formatting. cat() is ideal for building output lines manually.
Script vs REPL
# script.R
print("Hello, World")
# REPL: type expressions at the > prompt
The playground runs scripts like Rscript script.R. The interactive console is great for exploration locally—similar to Python's REPL.
Important interview questions and answers
- Q: What prints text in R?
A:print()andcat()—use cat for formatted strings without extra quoting. - Q: Is a main function required?
A: No—top-level statements run when the script executes; packages useif (interactive())patterns locally.
Self-check
- Which function adds quotes around character output by default?
- What runs an .R file from the shell?
Tip: Use cat() when building formatted lines; print() when inspecting whole objects.
Interview prep
- print vs cat?
print()shows object representation;cat()writes strings without default quoting.