I would like to assign a multi-line string to a variable in R so that I can call the variable later.
When I try paste("line 1", "line 2", sep = "\n") I get "line 1\nline 2".
When I try cat("line 1", "line 2", sep = "\n"), I get the desired output, but this is output is not persistent (cat() returns an object of type None). The reason that I’m trying to use a multi-line string is that I need to send query results via a SMTP server (and the package sendmailR) in the message body (not as an attachment).
I would like to assign a multi-line string to a variable in R so
Share
paste("line 1", "line 2", sep = "\n")is the right way, you get what you intended:Your confusion probably comes from the fact that
printescapes the output, so it is printing the string the way it would be expected by the parser:Note the quotes around the string.
catprints the output as-is. In both cases the object is the same, it’s only the output format that differs.Obviously, you could create the string directly without
paste: