R functions to automatically save plots and data frames