R: Find file paths that exist

existing_files {xfun} | R Documentation

## Find file paths that exist

### Description

This is a shorthand of `x[file.exists(x)]`, and optionally returns the first existing file path.

### Usage

    existing_files(x, first = FALSE, error = TRUE)

### Arguments

`x` | A vector of file paths.
`first` | Whether to return the first existing path. If `TRUE` and no specified files exist, it will signal an error unless the argument `error = FALSE`.
`error` | Whether to throw an error when `first = TRUE` but no files exist. It can also take a character value, which will be used as the error message.

### Value

A vector of existing file paths.

### Examples

    xfun::existing_files(c("foo.txt", system.file("DESCRIPTION", package = "xfun")))

[Package xfun version 0.31 Index]