createFilename {utilitiesR} | R Documentation |
create a file path based off a given format.
createFilename(format, fPath = format, base = "", extraTokens = list())
format |
A file format optionally containing the following tokens, which will be replaced from the "base" and "fPath" arguments. item%dthe parent directory of the file in fPath item%Ddirname(fPath) item%ethe extension of the file in fPath (default "tif") item%fthe file name of the file in fPath item%Bthe "base" parameter supplied in the arguments. |
fPath |
A filepath to grab "%d", "%D", etc from. |
base |
what to be used as "%B" in "format". |
extraTokens |
A named list, with further token=value
pairs to be substituted in 'format'. Does not include
the '%', so if we wanted '%a' to be substitued by
'foobar', we would specify |
a file name with all the tokens substituted in.
Other file: getExtension
,
getFilename
,
getUniqueFilename
,
makeIfNotExists
createFilename('%B/%d/%f_new.%e', fPath='/path/to/file.txt', base='/new/root/dir') # returns '/new/root/dir/to/file_new.txt' createFilename('%D/%f_smaller.jpg', fPath='~/pictures/img.jpg') # returns '~/pictures/img_smaller.jpg' # demonstrate the ... parameter. '%a' is substituted with '_', # '%b' is substituted with nchar('foobar.txt'). createFilename('%f%a%b.png', fPath='foobar.txt', extraTokens=list(a='_', b=function(fpath, base) { nchar(fpath) })) # returns 'foobar_10.png'