6.6 Glue Pipelines

20180729 We can use glue::glue_data() within pipes and operate over the rows of the data that is piped into the operator.

weatherAUS %>%
  sample_n(6) %>%
  glue_data("Observation",
            " {rownames(.) %>% as.integer() %>% comma() %>% sprintf('%7s', .)}",
            " location {Location %>% sprintf('%-14s', .)}",
            " max temp {MaxTemp %>% sprintf('%5.1f', .)}")
## Observation     1.0 location Perth          max temp  24.9
## Observation     2.0 location SydneyAirport  max temp  22.9
## Observation     3.0 location Canberra       max temp  44.0
## Observation     4.0 location Williamtown    max temp  21.0
## Observation     5.0 location Hobart         max temp  18.5
## Observation     6.0 location SydneyAirport  max temp  21.8

It can also be useful with the tidy verse work flow.

weatherAUS %>%
  sample_n(6) %>%
  mutate(TempRange = glue("{MinTemp}-{MaxTemp}")) %>%
  glue_data("Observed temperature range at {Location} of {TempRange}")
## Observed temperature range at MountGambier of 9-15.7
## Observed temperature range at Nuriootpa of 18.5-38.4
## Observed temperature range at Watsonia of 5.9-14.8
## Observed temperature range at Ballarat of 4.9-18.5
## Observed temperature range at Hobart of 11.6-17.7
## Observed temperature range at Watsonia of 8.6-32.5


Your donation will support ongoing development and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.