Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (5.3k points)
edited by

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
edited 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 

>

Browse Categories

...