Prepend (or postpend) a filename with a prefix (or suffix). If the directory name of the file cannot be ascertained from its path, it is assumed to be in the current working directory.

.prefix(f, prefix = "")

.suffix(f, suffix = "")

Arguments

f

A character string giving the name/path of a file.

prefix

A character string to prepend to the filename.

suffix

A character string to postpend to the filename.

Value

A character string or vector with the prefix pre-pended or suffix post-pended on the basename of the f, before the file extension.

Author

Jean Marchal and Alex Chubaty

Examples

# file's full path is specified (i.e., dirname is known)
myFile <- file.path("~/data", "file.tif")
.prefix(myFile, "small_") ## "/home/username/data/small_file.tif"
#> [1] "/home/runner/data/small_file.tif"
.suffix(myFile, "_cropped") ## "/home/username/data/myFile_cropped.shp"
#> [1] "/home/runner/data/file_cropped.tif"

# file's full path is not specified
.prefix("myFile.shp", "small") ## "./small_myFile.shp"
#> [1] "./smallmyFile.shp"
.suffix("myFile.shp", "_cropped") ## "./myFile_cropped.shp"
#> [1] "./myFile_cropped.shp"