← Back to R Course | Chapter 1: Getting Started | Lesson 5 of 6

print() and cat()

print and cat are two ways to show things on the screen: print shows a value neatly, while cat writes plain text like a simple message. It is the way R speaks back to you.

In this page:

  1. print() and cat()
Syntax
r
print(object)
cat("text", value, "\n")

print() and cat()

print() displays an R object using its formatted representation, including quotes around strings and type-specific formatting.

cat() concatenates and prints its arguments as raw text with no quotes, and is often used for cleaner, more readable output. Both are the primary ways to produce output in an R script.

Note:
  • Use cat() when you want clean, human-readable output.
  • Use print() to see an object's full, unambiguous representation.

Example: print() and cat()

markup
print("Hello, World!")
cat("Hello, World!\n")

x <- c(1, 2, 3)
print(x)
cat("Vector:", x, "\n")
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Using print("a", "b") to print two values, when the second argument is not part of the message; use cat or paste.
  2. Forgetting \n in cat("Hello"), so the next output stays on the same line.
  3. Expecting cat() to work on a list or data frame, which gives an error, when print() handles those.
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.