2

I'd like to build a character value with the month name in it. I can extract the month name by using today() >%> months(), but as soon as I pipe the result into glue(), and start using the placeholder (.), the value behind the placeholder gets duplicated. Does anybody know what's going on here?

library(lubridate)
library(glue)
library(magrittr)

# returns month name as character
today() %>% 
  months()
#> [1] "April"

# when piping into glue(), I get an unexpected output
today() %>% 
  months() %>% 
  glue("my_test_{.}")
#> Aprilmy_test_April

Created on 2019-04-04 by the reprex package (v0.2.1)

Zoe
  • 27,060
  • 21
  • 118
  • 148
piptoma
  • 754
  • 1
  • 8
  • 19
  • Is there a reason you can't use `paste`? For example, `paste0("my_test_", .)`. – A. Stam Apr 04 '19 at 11:54
  • yes, I could use `paste()` but my actual code is more complex, and I'd like to make use of glues improved readability – piptoma Apr 04 '19 at 12:04
  • Based on your current question, `paste` would be the preferred solution. `glue` requires named arguments, which is why it struggles when you pipe a nameless string. If you think `paste` won't work in your situation, can you alter the question so that it resembles your actual code more closely? – A. Stam Apr 04 '19 at 12:42

0 Answers0