This is a shorthand of x[file.exists(x)], and optionally returns the
first existing file path.
Arguments
- x
A vector of file paths.
- first
Whether to return the first existing path. If
TRUEand no specified files exist, it will signal an error unless the argumenterror = FALSE.- error
Whether to throw an error when
first = TRUEbut no files exist. It can also take a character value, which will be used as the error message.
Examples
xfun::existing_files(c("foo.txt", system.file("DESCRIPTION", package = "xfun")))
#> [1] "/tmp/Rtmp9c93ZR/temp_libpath38d7f7207ce56b/xfun/DESCRIPTION"