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 = "")
A character string or vector with the prefix pre-pended or suffix post-pended
on the basename
of the f
, before the file extension.
# 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"