coding
coding

Reputation: 1207

Cant schedule R script with cron

This is my crontabenter image description here

It´s supposed that my script on R saves csv on my directory.

write.csv(raw_data, paste0("/Users/marianafernandez/Desktop/prueba/data-raw/database_pulls/raw_data/raw_data_", Sys.Date(), ".csv"), na = "", row.names = F)

If I run on my terminal: R Script scraping.R everything goes fine. But when I try to do my cronjob is not working, nothing happens. Help me please

Upvotes: 0

Views: 254

Answers (2)

NoMoreHugs
NoMoreHugs

Reputation: 51

cron is still supported by OSX but it has been deprecated in launchd.

You need to create a "plist" file and place it in folder ~/Library/LaunchAgents. Example plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>example</string>
    <key>ProgramArguments</key>
    <array>
      <string>Rscript /path/to/example.R</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
      <key>Minute</key>
      <integer>0</integer>
      <key>Hour</key>
      <integer>23</integer>
    </dict>
  </dict>
</plist>

You need to load this plist file into the launchd scheduler and start it:

 launchctl load ~/Library/LaunchAgents/example.plist
 launchctl start example

Name example corresponds to the field Label in the plist file.

Upvotes: 1

sconfluentus
sconfluentus

Reputation: 4993

More likely than not you need to put the path TOO the Rscript in front of it path/to/Rscript and it will correct the problem...that worked for me.

Upvotes: 1

Related Questions