Skip to content

Instantly share code, notes, and snippets.

@GuillaumePressiat
Created March 24, 2019 10:57
Show Gist options
  • Save GuillaumePressiat/f2d4ac48b12920ef501a00abf5a2fb99 to your computer and use it in GitHub Desktop.
Save GuillaumePressiat/f2d4ac48b12920ef501a00abf5a2fb99 to your computer and use it in GitHub Desktop.
Strength of a Lennon song exposed with R function glue::glue
library(stringfix)
library(magrittr)
one <- c('love', 'is', 'real')
(one %c% ' ') %,% (rev(one) %c% ' ')
love_verse <- function(w1, w2, w3){
glue::glue(
"Love is {b}, {b} is love
Love is {y}, {y} love
Love is {u} to be loved",
b = w1, y = w2, u = w3)
}
love_verse('real', 'feeling', 'wanting')
love_verse('touch', 'reaching', 'asking')
love_verse('free', 'living', 'needing')
list(list(w1 = 'real', w2 = 'feeling', w3 = 'wanting'),
list(w1 = 'touch', w2 = 'reaching', w3 = 'asking' ),
list(w1 = 'free', w2 = 'living', w3 = 'needing')) %>%
purrr::map(function(x)do.call(love_verse, x))
@GuillaumePressiat
Copy link
Author

@jimhester Thank you !
This is nice indeed. Tidy way.
In fact I use glue_data often but have not thinked theses words will fit in a 3*3 tibble/tribble for using that way !
I will update blogpost with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment