str_c() and missing values
df <- tibble(name = c("Flora", "David", NA))
df |>
mutate(
greeting0 = str_c("Hi ", name, "!"),
greeting1 = str_c("Hi ", coalesce(name, "you"), "!"),
greeting2 = coalesce(str_c("Hi ", name, "!"), "Hi!")
)
## # A tibble: 3 × 4
## name greeting0 greeting1 greeting2
## <chr> <chr> <chr> <chr>
## 1 Flora Hi Flora! Hi Flora! Hi Flora!
## 2 David Hi David! Hi David! Hi David!
## 3 <NA> <NA> Hi you! Hi!