0

I've just set up an R script to run on my Windows machine - I'm trying to have it save a dataframe on the working directory (which I know from getwd()).

I can see from the Task Scheduler that the script must be running as saves the last run time, however when I check the wd for new time stamps on the dataframes I'm trying to save, they haven't updated? (I save over them each time, or at least that's what I'd like to do, I manually saved them in there to start with).

I'm using this on the scheduler:

C:\Program Files\R\R-2.13.1\bin\R.exe" CMD BATCH  --vanilla --slave “C:\my projects\my_script.R

That appears to be working, but can anyone offer a reason as to why the script that I call doesn't seem to be saving my NEW DF to the wd? I'm using this command to save the DF:

write.table(m23,file="m23.csv",sep=",",row.names=F)

so DF m23 should get updated everyday in the wd when the scheduler calls the script at 6am?

Paul.

Csislander
  • 2,100
  • 1
  • 13
  • 16
PaulBeales
  • 475
  • 1
  • 8
  • 21
  • by the way if I run all of this manually the data is there...so its not a case of 'nothing to save' – PaulBeales May 12 '14 at 12:31
  • I have some scripts that save graphics files. I've observed that (sometimes?) time stamps are not updated in Windows Explorer even though files were overwritten. Are you sure that the files were not updated? (You could try writing a time stamp into the file.) – Roland May 12 '14 at 12:41
  • good point...I hadnt physiccally checked the contents to see if they changed or not..just assumed it didnt... – PaulBeales May 12 '14 at 12:44
  • I reran it and checked the contents of the dataframe...it has not changed. So it looks like I'm back to the original problem.. – PaulBeales May 12 '14 at 13:03

1 Answers1

0

Are you sure you know what the current working directory is when the scheduler runs the script? My guess is it might not be what you think is it. I would look at the answers to this question: Rscript: Determine path of the executing script, especially the suggestion about using commandArgs to figure out where you are. Or you can explicitly set the working directory in your script with setwd()

Community
  • 1
  • 1
MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Or put an absolute path in the file name. – Roland May 12 '14 at 13:13
  • Thanks for the feedback guys....im currently trying the "explicitly defining the wd" to see if that works.... – PaulBeales May 12 '14 at 13:57
  • OK so I set my wd inside the script (at the beginning) using setwd() but the Dataframe still isn't saving to the location specified in the setwd function..? in fact if I do a *.csv search on the C Drive..I can't see it anywhere. I'm starting to wonder if its a scheduler problem..ie its not actually running or doing what I think it is. – PaulBeales May 12 '14 at 14:35
  • One thing i noticed when doing this manually in R...the file isnt writtwen until I press return on the last line of my script (The write table line)...not sure why. So Ive added in a meaningless line at the end of the r Script to ensure the ''return'' is forced and the write table executes...this sounds silly I know, but the timestamp only updated when I hit the return key and forced the command prompt to reval. – PaulBeales May 12 '14 at 15:26