Return the newest file from a vector of files

newestFile(x, timecol = "mtime", n = 1, ...)

Arguments

x

character vector of files, specifying file path where required.

timecol

character value from the output of base::file.info() indicating the time column used to order files. By default "mtime" refers to the time the file was last modified.

n

integer number of files to return, in order of the most recent to the least recent. By default n=1 returns only the one newest file.

...

additional parameters are ignored.

Value

Character vector length=1 of the most recently modified file from the input vector x. Note that any files not found are removed, using base::file.exists().

Details

This function returns the newest file, defined by the most recently modified time obtained from base::file.info().

Examples

newestFile(list.files());
#> [1] "nameVectorN.html"