Simple If Statement (Making Choices)
To determine if a file named thesis_data.csv exists in your working directory
you can use the code to get a list of available files and directories:
list.files()
- Use the
%in%operator to write a conditional statement that checks to see ifthesis_data.csvis in this list. - Write an
ifstatement that loads the file usingread_csv()only if the file exists. - Add an
elseclause that prints “OMG MY THESIS DATA IS MISSING. NOOOO!!!!” if the file doesn’t exist. - Make sure your actual thesis data is backed up.