1

So here's the problem There's a requirement to input newline (to process URL),

Basically it's like this in Python:

canonical_request = method + '\n' + canonical_uri + '\n' + canonical_querystring

I have tried using paste but whenever I use "\n" this character is included in the string.

I know a lot of people recommended cat but cat is for printing purposes, therefore you can make it into a variable such as

canonical_request <- cat(method, "\n", canonical_uri, "\n", canonical_querystring)

if you call canonical_request this way, it will give NULL

Do you know how to insert newline (by concatenating characters) in R?

ps. it's different from question here: R - new line in paste() function (OP doesn't state clearly the purposes of new line usage, I'm assuming it's for printing purposes)

Community
  • 1
  • 1
piwpiw
  • 11
  • 1
  • 4
  • I think this could help you: http://stackoverflow.com/questions/8112786/how-to-split-the-main-title-of-a-plot-in-2-or-more-lines – CFM Mar 15 '16 at 12:11
  • Possible duplicate of [R - new line in paste() function](http://stackoverflow.com/questions/26022378/r-new-line-in-paste-function) – Liesel Mar 15 '16 at 12:13
  • 1
    `paste` does exactly what you want. You simply misinterpret the output when printing it. – Konrad Rudolph Mar 15 '16 at 12:59
  • @KonradRudolph I see, i get your point now. thank you! – piwpiw Mar 16 '16 at 02:32

1 Answers1

5

as you mentioned cat() is used for printing puposes. It interpretes "\n" as a linebreak, but does not return you a concenated character. Therefore to concenate the character you could use paste() and then call cat() to print it:

method = "method"
canonical_uri = "canonical_uri"
canonical_querystring = "querystring"
out <- paste(method, "\n", canonical_uri, "\n", canonical_querystring,sep = "")
cat(out)
David Go
  • 810
  • 1
  • 7
  • 13