Strength of a Lennon song exposed with R function glue::glue

This post is an actualisation with addendum below.
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)
}
As a return, parameters sometimes give echoes of poetry.
love_verse('real', 'feeling', 'wanting')
Love is real, real is love
Love is feeling, feeling love
Love is wanting to be loved
love_verse('touch', 'reaching', 'asking')
Love is touch, touch is love
Love is reaching, reaching love
Love is asking to be loved
## refrain
Love is you
You and me
Love is knowing
We can be
love_verse('free', 'living', 'needing')
Love is free, free is love
Love is living, living love
Love is needing to be loved
https://www.youtube.com/watch?v=7er_xx7Wmg8
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))
[[1]]
Love is real, real is love
Love is feeling, feeling love
Love is wanting to be loved
[[2]]
Love is touch, touch is love
Love is reaching, reaching love
Love is asking to be loved
[[3]]
Love is free, free is love
Love is living, living love
Love is needing to be loved
We could also read title of this article as “strength of an R function exposed with a Lennon song”…
If you like it, you can view this code as a gist here.
Addendum
In a more tidyverse way, you could also do this last piping block step using glue_data
approach, what I have not thinked about.
I haven’t been able to think theses words will fit in a tibble, which is why I have used do.call
which sounds a little like old.school
!
With a little help from Jim Hester, it’s getting better:
library(magrittr)
tibble::tribble(
~a, ~b, ~c,
"real", "feeling", "wanting",
"touch", "reaching", "asking",
"free", "living", "needing"
) %>%
glue::glue_data(
"Love is {a}, {a} is love
Love is {b}, {b} love
Love is {c} to be loved",
) %>%
glue::glue_collapse("\n\n")
#> Love is real, real is love
#> Love is feeling, feeling love
#> Love is wanting to be loved
#>
#> Love is touch, touch is love
#> Love is reaching, reaching love
#> Love is asking to be loved
#>
#> Love is free, free is love
#> Love is living, living love
#> Love is needing to be loved