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.
give_ext(string, ext, replace = FALSE)
The intended file name.
The intended file extension (with or without the ".").
If the file has an extension already, replace it (or append the new extension name)?
A string: the file name in your intended form.
# NOT RUN {
give_ext(c("abc", "abc.csv"), "csv")
give_ext("abc.csv", "pdf")
give_ext("abc.csv", "pdf", replace = TRUE)
# }
Run the code above in your browser using DataLab