4.4 Saving your work
Always save your work! Early and often! This is true both of both your scripts and your data sets. R will ask if you want to save your “workspace” when you close the session, and you should not. Save your script instead.
4.4.1 Saving an R script
To save you .r script file in RStudio, go to File - Save (or Save As…). You can also use the keyboard shortcut Ctrl + S.
4.4.2 Saving a data frame
To save a data frame as a .rdata data file, use the save(object,'filename') command. To save a data frame as (i.e. write it onto) a .csv file, use the write_csv(object, 'filename') command and enter the name of the object and the file name.
save(film, file = 'film.rdata') # save object film as an Rdata file
write_csv(film, file = 'film.csv') # save object film as a CSV fileAs always, these actions will write the new file to your working directory. If you have not specified a working directory, or if you want to save elsewhere, specify the complete path name here.