2

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
obewanjacobi
  • 458
  • 2
  • 12
  • 1
    Have you checked the log file? It might tell you where the problem arises. You will likely also have to specify the entire path when writing to a file. Lastly, you can try setting `Sys.setenv("HOME" ="your_path")` and/or `setwd("your_path")` in the beginning of your script. Hope this helps! – Peer Christensen Aug 13 '19 at 20:58
  • 1
    This may sound dumb, but I attempted to find the log file but couldn't. Setting the system environment though didn't work :/ – obewanjacobi Aug 14 '19 at 13:31

2 Answers2

2

I had similar troubles finding a file written from a scheduled job in R.

I ended up finding the file in this system folder: C:\Windows\System32

  • R version = 4.0.0
  • Windows10 Machine

Optionally, you could modify the R Script to put the file in a more familiar location.

for example:

OutPath<-'C:/Users/power/Desktop/YOUR.FILE.NAME.HERE.csv'
write.csv(YOUR.DATAFRAME.HERE,file = OutPath)
TylerH
  • 20,799
  • 66
  • 75
  • 101
zach
  • 759
  • 1
  • 9
  • 21
1

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.

obewanjacobi
  • 458
  • 2
  • 12