Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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

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 = "  ")



[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)


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

Browse Categories