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 Sahiti
• 6,370 points
596 views

1 answer to this question.

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,090 points

Related Questions In Data Analytics

0 votes
3 answers

How to write lines to a text file in R?

sink("outfile.txt") cat("hello") cat("\n" ...READ MORE

answered May 24, 2019 in Data Analytics by anonymous
18,572 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,720 points

edited Jun 9, 2020 by MD 8,523 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 17, 2018 in Data Analytics by DataKing99
• 8,240 points
1,631 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 Sahiti
• 6,370 points
1,549 views
0 votes
1 answer

Big Data transformations with R

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

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,610 points
762 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,660 points
834 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,660 points
5,542 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

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

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
854 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 6, 2018 in Data Analytics by kappa3010
• 2,090 points
1,414 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP