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.csv
is in this list. - Write an
if
statement that loads the file usingread.csv()
only if the file exists. - Add an
else
clause that prints “OMG MY THESIS DATA IS MISSING. NOOOO!!!!” if the file doesn’t exist. - Make sure your actual thesis data is backed up.