This function replaces the file extension of a given filename with a specified new extension.
It validates the input to ensure the filename and the new extension are single character strings.
Then, it replaces the old extension with the new one and returns the modified filename.
Usage
replace_file_extension(filename, new_extension)
Value
A character string representing the filename with the replaced file extension.
Arguments
filename
The input filename as a character string.
new_extension
The new file extension to replace the old one (including the dot, e.g., ".bib").
if (FALSE) {
# Replace the file extension of a text file with a BibTeX extensionnew_filename <- replace_file_extension("example_document.txt", ".bib")
print(new_filename) # "example_document.bib"}