Check the names of every file in the working directory

First, we will check how many files are available in our directory so for that, we will use list.files() function so it will check how many files are present in our current directory.

R




list.files()


Output:

  [1] "benchmark.png"       "dashboard.pbix"      "data.csv"           
[4] "data.xlsx" "desktop.ini"

Now we will check whether the particular file is existing or not in our directory. for that, we have several methods.

How to check if a file already exists in R ?

In this article, we will discuss how to check if a file already exists or not using R Programming Language.

Directory in use:

Similar Reads

Check the names of every file in the working directory

First, we will check how many files are available in our directory so for that, we will use list.files() function so it will check how many files are present in our current directory....

Method 1: Using File.exists()

...

Method 2: Using file_test()

The function file.exists() returns a logical vector indicating whether the file mentioned in the function existing or not....

Method 3: if elseĀ statement to import a file only if it exists or not

...

Contact Us