I am having problems when trying to run my R script using Rscript
via crontab
.
The following command works fine when running in the command line
Rscript /var/www/html/sent/sentiment/code/parse.r
But the following line inside crontab
*/5 * * * * Rscript /var/www/html/sent/sentiment/code/parse.r > /var/www/html/sent/sentiment/code/backup.log 2>&1
Will return the following error in the log
Error in library(twitteR) : there is no package called 'twitteR'
Execution halted
Why is it possible that Rscript won't be able to find the packages when running using cron? How can I make crontab 'see' my R packages.
Any tip much appreciated.
As suggested in the comments, the problem might be that you and your crontab are using a different R install.
To check if it is the case, run which Rscript
as yourself and as crontab.
If they are different (which I suspect), you could use the full path to the appropriate Rscript
when you are calling it from crontab. A more permanent solution would require setting environment variables.
It will most likely be your .libPath()
setting -- which is why I instrument to the Debian/Ubuntu package to use a system-wide, rather than per-user, setting.
To check, run as you as well as from the same crontab
print(.libPaths())
print(installed.packages())
The difference should become clear. I think I answered an almost identical question here before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With