Use file.exists for specific directory that is NOT the working directory

Can you use file.exists() to test whether a file exists in a directory that is NOT the working directory? To say it another way, can you use file.exists() while specifying a specific file path? I know it works to test the current working directory but I want to check a different directory.

If not, how could you test to see if a file exists in a directory other than the working directory?

All you have to do is include the path in the file name.

file.exists("~/R/Play/Dummy.csv")
[1] TRUE

Okay thank you - but is there a way to test whether a file exists in a specific directory using file name and file path as 2 separate arguments? I am trying to integrate a way to test file existence using both file name and file path as pre-existing objects (ie file -> "Dummy.csv" and path -> "~/R/Play".)

Okay you can just paste them together - got it. Thanks

Use file.path() as that will paste them together with the preferred system seperator

Good point - thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.