R console output only shows most recent command in if condition

0 votes
In RStudio, if I execute this code:

"1 + 1 is: percent d," sprintf(1+1),
"2 + 2 is: percent d," sprintf(2+2)

If (1), then sprintf("1 + 1 is: percent d", 1+1) and sprintf("2 + 2 is: percent d," 2+2) are appropriate.
This is what I receive:

"1 + 1 is: percent d," sprintf(1+1),
[1] sprintf("1 + 1 is: 2," "2 + 2 is: percent d", 2+2)
[1] "2 + 2 is: 4" > \s> if (1+sprintf "1 + 1 is: percent d", 1+1)
+ sprintf("%D is: 2 + 2 is:", 2+2)
+ } [1] "2 Plus 2 is: 4"
Why doesn't the 1+1 line, which is the initial print statement in the if(1) condition, print to the console as well, I wonder? Every time I have a "if" condition with numerous output lines that I want to print or plot, it seems that only the final one displays. How do I repair this?
Jul 5, 2022 in Data Science by avinash
• 1,840 points
284 views

No answer to this question. Be the first to respond.

Your answer

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

Related Questions In Data Science

0 votes
1 answer

R command for setting working directory to source file location in Rstudio

Yes, you can specify your working directory ...READ MORE

answered Sep 8, 2023 in Data Science by anonymous
• 1,380 points
684 views
0 votes
0 answers

Introduction to Statistical Learning with Applications in R Figure Codes

I recently bought the following book: An Introduction ...READ MORE

Jun 1, 2022 in Data Science by avinash
• 1,840 points
562 views
0 votes
1 answer

Difference between the == and %in% operators in R

percent in percent "returns a vector of ...READ MORE

answered Jun 20, 2022 in Data Science by Sohail
• 3,040 points
723 views
0 votes
1 answer

Difference between the == and %in% operators in R

According to help('percent in percent'), percent in ...READ MORE

answered Jun 23, 2022 in Data Science by Sohail
• 3,040 points
496 views
0 votes
1 answer

How to make loop for one-at-a time logistic regression in R?

You're probably looking for something similar to ...READ MORE

answered Jun 20, 2022 in Data Science by Sohail
• 3,040 points
1,036 views
0 votes
1 answer

do-while loop in R

Unlike for and while loops, which test the loop condition at ...READ MORE

answered Jun 1, 2022 in Data Science by Sohail
• 3,040 points
665 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,570 points
1,030 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
1,178 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,890 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
1,112 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