How to print new lines with print() in R?

0 votes

I am trying to print a multiline message.

For example,

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

I got the output as follows:

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

My desired output is as follows:

Image not supplied.
Usage: ./program F=filename
May 3, 2018 in Data Analytics by darklord
• 6,140 points
12 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You can use cat() instead of writeLines():

 writeLines("Image not supplied.\nUsage: ./program F=filename")
 Image not supplied.
 Usage: ./program F=filename

You don't have to remember to append a "\n" to the string passed to cat() to get a newline after your message.

 E.g. Compare the same above output:

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

and

 cat("Image not supplied.\nUsage: ./program F=filename","\n")
Image not supplied.
Usage: ./program F=filename
answered May 3, 2018 by kappa3010
• 2,010 points

Related Questions In Data Analytics

0 votes
1 answer

How to write lines to a text file in R?

It is easy and simple: fileConn<-file("abc.txt") writeLines(c("H ...READ MORE

answered Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,700 points
514 views
0 votes
1 answer

How to plot side-by-side Plots with ggplot2 in R?

By Using gridExtra library we can easily ...READ MORE

answered Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,700 points
906 views
0 votes
1 answer

How to filter a data frame with dplyr and tidy evaluation in R?

Requires the use of map_df to run each model, ...READ MORE

answered May 16, 2018 in Data Analytics by DataKing99
• 8,100 points
40 views
0 votes
1 answer

How to calculate group mean and assign it to new data in R

You can use something like this: df$grp.mean.values <- ...READ MORE

answered Jun 27, 2018 in Data Analytics by darklord
• 6,140 points
36 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 17, 2017 in Data Analytics by Sudhir
• 1,610 points
27 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
26 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
32 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
61 views
0 votes
1 answer
0 votes
1 answer

How to join two tables (tibbles) by *list* columns in R

You can use the hash from digest ...READ MORE

answered Apr 5, 2018 in Data Analytics by kappa3010
• 2,010 points
34 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.