Schedule a Rscript crontab everyminute
I can see the dreaded smart quotes in your cron entry. This often happens when you copy-paste from word processors. Backspace over those abominations and re-type normal quotes. Change:
* * * * * Rscript “/Users/Home/Desktop/David Studios/Scraper/compiler.R”
to
* * * * * Rscript "/Users/Home/Desktop/David Studios/Scraper/compiler.R"
See the difference? It's subtle and easy to miss.
Update:
I see you've made the above change and it's still not working for you. Verify that Rscript
is in the $PATH
environment variable for the user that owns this crontab. Alternatively, you can simply specify the fully qualified path to Rscript
directly in the cron entry. You can find that quickly on the command line with the following command:
which Rscript
Update #2:
I see by your comments that the fully qualified path to Rscript
is /usr/local/bin/Rscript
. I'm guessing /usr/local/bin
is not in the path for the user who owns this crontab. Try using the fully qualified path, like this:
* * * * * /usr/local/bin/Rscript "/Users/Home/Desktop/David Studios/Scraper/compiler.R"
Cant schedule R script with cron
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>
Schedule R script using cron
Consider these tips
Use Rscript (or littler) rather than
R CMD BATCH
Make sure the cron job is running as you
Make sure the script runs by itself
Test it a few times in verbose mode
My box is running the somewhat visible CRANberries via a cronjob calling an R script
(which I execute via littler but Rscript
should work just as well). For this, the entry in /etc/crontab
on my Ubuntu server is
# every few hours, run cranberries
16 */3 * * * edd cd /home/edd/cranberries && ./cranberries.r
so every sixteen minutes past every third hour, a shell command is being run with my id. It changes into the working directory, and call the R script (which has executable modes etc).
Looking at this, I could actually just run the script and have setwd()
command in it....
How to schedule an R Script Cronjob in a linux server?
The following cron job will run Rscript scriptSecos.R
from the path /home/script2
, once a day, at 0:00 (midnight).
0 0 * * * cd /home/script2; Rscript scriptSecos.R >/dev/null 2>&1
If you want to save the output of the script to a file, change >/dev/null
with >/path/to/file
.
You can copy and paste this cronjob in your crontab file (You can open the file by using command crontab –e
)
Run cron job within RStudio
Thank you Dirk.
Yes I did add already #!/usr/bin/Rscript
to my script.
The problem actually came from the simple fact that some libraries were not loaded in my script, causing errors and stopping the script.
Now that all the libraries are loaded, it is working fine!
Related Topics
Draw the Sum Value Above the Stacked Bar in Ggplot2
Cut Function in R- Labeling Without Scientific Notations for Use in Ggplot2
Select Only the First Row When Merging Data Frames with Multiple Matches
How Do Keep Only Unique Words Within Each String in a Vector
How to Insert New Line in R Shiny String
Rotate a Matrix in R by 90 Degrees Clockwise
Converting a Data Frame to Xts
How to Use Spread on Multiple Columns in Tidyr Similar to Dcast
In R Markdown in Rstudio, How to Prevent the Source Code from Running Off a PDF Page
Why and Where Are \N Newline Characters Getting Introduced to C()
Sparklyr: How to Center a Spark Table Based on Column
Split Delimited Single Value Character Vector
How to Organize Large R Programs
R Apply Function with Multiple Parameters
Fill in Missing Values by Group in Data.Table
Subsetting Data.Table Using Variables with Same Name as Column