You can check if directory exists or not using dir.exist() function in R. This function takes directory path and return output in logicaal value.

The following method shows how you can do it with syntax.

Method: Use dir.exist() Function

dir.exist(path_of_directory)

The following example shows how to check if directory exists or not.

Using dir.exist() Function

Suppose we have /Documents/R Studio patb of directory and want to check is this directory exist or not:

# Declare directory path
path <- "/Documents/R studio"

# Check directory exists or not
dir.exists(path)

Output:

[1] TRUE

This output gives TRUE which means that directory is exist.