Print string and variable contents on the same line in R
You can use paste
with print
print(paste0("Current working dir: ", wd))
or cat
cat("Current working dir: ", wd)
Or using message
message("Current working dir: ", wd)
@agstudy's answer is the more suitable here
{glue} offers much better string interpolation, see my other answer. Also, as Dainis rightfully mentions,
sprintf()
is not without problems.
There's also sprintf()
:
sprintf("Current working dir: %s", wd)
To print to the console output, use cat()
or message()
:
cat(sprintf("Current working dir: %s\n", wd))
message(sprintf("Current working dir: %s\n", wd))