Learn R Programming

xfun (version 0.48)

existing_files: 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)

Value

A vector of existing file paths.

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.

Examples

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

Run the code above in your browser using DataLab