Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k points)
edited by

Is there a way to print text and variable contents on the same line? For example,

wd <- getwd()

print("Current working dir: ", wd)

I couldn't find anything about the syntax that would allow me to do this.

1 Answer

0 votes
by

You can use the paste function from the base package to print strings and variable contents on the same line, as follows:

wd <- getwd()

str <- paste("Current working directory is", wd, sep = "  ")

str

Output:

[1] "Current working directory is C:/Users/intellipaat/Documents"

You can also use the stprintf() function as follows:

sprintf("Current working directory is %s", wd)

Output:

[1] "Current working directory is C:/Users/intellipaat/Documents"

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...