Helper function allowing to quckly change the extension of a file name

change_fileext(in_file, new_ext = NULL, new_path = NULL)

Arguments

in_file

character full path of a file

new_ext

character new file extension (e.g., ".png"). If NULL (the default), the basename without extension is return, Deafault: NULL

new_path

character if not NULL the returned file name will use this new path instead than the one of the original file. If equal to "", only the updated basenmae is therefore returned (see examples), Default: NULL

Value

character basename/full_path of `in_file`` with updated extension

Examples

in_file = "home/lb/tmp/prova.tif" # return an updated full_path change_fileext(in_file, ".png")
#> [1] "home/lb/tmp/prova.png"
#' update both path and extension change_fileext(in_file, ".png", new_path = "/home/lb/new_path")
#> [1] "/home/lb/new_path/prova.png"
# return an updated basename change_fileext(in_file, ".png", new_path = "")
#> [1] "prova.png"