Display Character String in Separate Newlines in R (2 Examples)

This R programming tutorial explains how to display a character string in separate lines in the RStudio console.

Example String

my_string <- "line one\nline two\nline three"          # Example string
my_string                                              # Printing string
# "line one\nline two\nline three"

Our example string is shown in a single line, if we print it with the default method. The following two examples illustrate how to print our string in separate newlines.

Example 1: Print to Newline with writeLines Function

writeLines(my_string)                                  # writeLines function
# line one
# line two
# line three

Example 2: Print to Newline with cat Function

cat(my_string)                                         # Apply cat function
# line one
# line two
# line three

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top