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
An alternative to
cat()iswriteLines():An advantage is that you don’t have to remember to append a
"\n"to the string passed tocat()to get a newline after your message. E.g. compare the above to the samecat()output:and
The reason
print()doesn’t do what you want is thatprint()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 likecat()andwriteLines()to display the string. I say “a version” because precision may be reduced in printed numerics, and the printed object may be augmented with extra information, for example.