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,170 points
29 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,020 points

Related Questions In Data Analytics

0 votes
2 answers

How to write lines to a text file in R?

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

answered May 24 in Data Analytics by anonymous
2,421 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
1,711 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,130 points
132 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,170 points
58 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
54 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
75 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
179 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
120 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,020 points
67 views