What is the file.exists() function in R?

Overview

The function file.exists() returns a logical vector indicating whether the files named by its argument exist.

Syntax

file.exists(filename)
Syntax for the file.exists() function

Parameter value

This function takes the parameter value filename. This represents character vectors containing file names.

Return value

This function returns logical values (TRUE or FALSE) if the file exists or not.

Example

# creating a new file
file.create("ABC.txt")
# renaming the file name
file.rename("ABC.txt", "XYZ.txt")
# checking if the file exists
file.exists("XYZ.txt")

Free Resources