0Pricing
R Academy · Lesson

Displaying Output with cat() and print()

Distinguish between cat() for console output and print() for objects.

print() — The Default Output Function

print() is R's default method for displaying objects. It uses the object's class to dispatch the right formatting method. In interactive sessions, typing a variable name is equivalent to calling print() on it.

x <- c(1, 2, 3, 4, 5)
print(x)
# Equivalent to:
x

cat() — Raw Character Output

cat() concatenates and outputs its arguments as raw text, with no surrounding quotes, no index markers like [1], and no newline at the end by default. It is designed for formatted text output, not for displaying R objects.

name <- 'Alice'
age  <- 30
cat('Name:', name, '\n')
cat('Age:', age, '\n')
cat('Score:', 92.5, '\n')

All lessons in this course

  1. Building Strings with paste() and paste0()
  2. Formatted Output with sprintf()
  3. Displaying Output with cat() and print()
  4. String Padding and Alignment
← Back to R Academy