createFilename {utilitiesR}R Documentation

create a file path based off a given format.

Description

create a file path based off a given format.

Usage

  createFilename(format, fPath = format, base = "",
    extraTokens = list())

Arguments

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 list(a='foobar'). The value will be coerced to character, unless it is a function, in which case it will be executed with arguments 'fPath' and 'base'.

Value

a file name with all the tokens substituted in.

See Also

Other file: getExtension, getFilename, getUniqueFilename, makeIfNotExists

Examples

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'

[Package utilitiesR version 2.0 Index]