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" |
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 |
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 |
cat(my_string) # Apply cat function # line one # line two # line three