Search code examples
rr-taskscheduler

R Script that Runs Daily and Writes a csv File


I am attempting to make an R script that will write a csv file to my working directory daily for me to check. I am trying to use the taskscheduleR package to do so, but it isn't behaving how I expected. Below is my code:

print("Running the Missing-Data Checker now.")

source('./functions/missing_data_checker.R') # this file contains a function 
                                             # to read in the data I need

dats = missing_chkr(as.character(Sys.Date()-30)) # the afformentioned function
missings = dats$missing_dats
rm(dats)

write.csv(missing, 'Missing_Data.csv', row.names = FALSE)

print("The job has been run.)

To schedule the task, I simply use the code

taskscheduler_create('missing_data_check','./daily_missingdata_check.R', 
                     "ONCE", starttime = format(Sys.time() + 3700, "%H:%M"))

When the tasks runs, I see a window open up, but nothing happens. No csv files are written, and I don't think it even reads in the data.


Solution

  • For the record, I found a workaround for this a long time ago and forgot to post. I ended up not using taskscheduleR at all and followed a walkthrough similar to the one on this website: https://bigdataenthusiast.wordpress.com/2016/09/10/scheduling-r-script-using-windows-task-scheduler/

    It's fairly straight forward, and once you build out the capabilities to run daily, you can set it and forget about it.