Say you want to ensure a name is fit to be the name of a csv file. Then, if the input doesn't end with ".csv", this function will tack ".csv" onto the end of it. This is vectorized over the first argument.
str_give_ext(string, ext, replace = FALSE)
A string: the file name in your intended form.
str_give_ext(c("abc", "abc.csv"), "csv")
#> [1] "abc.csv" "abc.csv"
str_give_ext("abc.csv", "pdf")
#> [1] "abc.csv.pdf"
str_give_ext("abc.csv", "pdf", replace = TRUE)
#> [1] "abc.pdf"