From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

file.access

file.access

- [Instructor] At some point you will create a program that reads from a file or writes to a file and it's polite to check to see if that file exists before you try to use it, and for that R provides file.access. Now, just a note during this demonstration, if you're using the example code you'll want to be sure to set your directory to something that contains an R data file 'cause I'm going to use that as an example so in R studio I back up to this directory and I go under More and I set this as my working directory. Now let's check to see if .R data exists and in line six is the simplest use of file.access. File.access.Rdata and I run that and it comes back and it says zero. Well, for file.access zero means true. Negative one is false which is not necessarily what you might expect. Normally you'd expect a one for success or zero if it fails. Just be aware of that odd behavior. Now how would you actually use that?…

Contents