I am demoing a new R environment at my work. The directory structure is a mystery, so I'm walking around in the R shell to discover what files there are. I just noticed that if I type dir("./NonExistentDirectory") the answer is character(0), which is no different from the output of dir("./ExistingButEmptyDirectory"). I would expect the former case to return an error along the lines of Error: directory './NonExistentDirectory' is non-existent. Is there a reason for R giving the output that it does?
This was a design decision. path (the first argument) is vectorized. The documentation says
If a path does not exist or is not a directory or is unreadable it is skipped.
That can be convenient. Note that dir.exists is available for checking existence of a directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With