filesstrings (version 0.4.0)

GiveExt: Ensure a file name has the intended extension.

Description

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 vectorised over the first argument.

Usage

GiveExt(string, ext, replace = FALSE)

Arguments

string

The intended file name.

ext

The intended file extension (with or without the ".").

replace

If the file has an extension already, replace it (or append the new extension name)?

Value

A string: the file name in your intended form.

Examples

Run this code
GiveExt(c("abc", "abc.csv"), "csv")
GiveExt("abc.csv", "pdf")
GiveExt("abc.csv", "pdf", replace = TRUE)

Run the code above in your browser using DataCamp Workspace