Search code examples
rr-glue

Preserving indentation with glue


When using the R package glue, the following code

glue("foo\n  bar")

results in

foo
bar

However, I would prefer it to produce

foo
  bar

I could do the following

. <- "  "
glue("foo\n{.}bar")

but it is ugly. Interestingly, the following works as intended:

glue('
foo
  bar')

but for some strange reason the following does not:

glue('foo
  bar')

Can you explain to me this behavior?


Solution

  • glue('foo\n   bar',.trim = FALSE)