tidyverse / magrittr

Improve the readability of R code with the pipe
https://magrittr.tidyverse.org
Other
957 stars 157 forks source link

magrittr does not work with sprintf properly? #184

Closed superkeyor closed 5 years ago

superkeyor commented 5 years ago

Hi, I wrote a pipe combing with sprintf. The first command does not work as expected, but the second can. Is there something I did wrong or something I should know about magrittr in this particular case?

c("col1",'col3') %>% sprintf('There are %s', paste0(.,collapse=','))  # gets a vector

c("col1",'col3') %>% paste0(.,collapse=',') %>% sprintf('There are %s', .)
hadley commented 5 years ago

The first is equivalent to:

c("col1",'col3') %>% sprintf(., 'There are %s', paste0(.,collapse=','))