0 votes
1 view
in R Programming by (6.5k 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 (25.3k points)

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"

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...