Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (5.3k points)

I am trying to print a multiline message in R. For example,

print("File not supplied.\nUsage: ./program F=filename",quote=0)

I get the output

File not supplied.\nUsage: ./program F=filename

instead of the desired

File not supplied.

Usage: ./program F=filename

1 Answer

0 votes
by

The print() function shows you a version of the object from the R level - in this case, it is a character string. You need to use other functions like cat() and writeLines() to display the string.

writelines()

> writeLines("File not supplied.\nUsage: ./program F=filename")

File not supplied.

Usage: ./program F=filename

In writelines() function, you do not need to append a "\n" to the string passed to get a newline after your message. 

cat()

> cat("File not supplied.\nUsage: ./program F=filename")

File not supplied.

Usage: ./program F=filename

> cat("File not supplied.\nUsage: ./program F=filename","\n")

File not supplied.

Usage: ./program F=filename 

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...