R cannot find some packages when running through crontab

I am having problems trying to run an R script using Rscript via crontab .

The following command works fine when run on the command line

 Rscript /var/www/html/sent/sentiment/code/parse.r 

But the next 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 to the log

 Error in library(twitteR) : there is no package called 'twitteR' Execution halted 

Why is it possible that Rscript cannot find packages when working with cron? How can I do crontab 'see' my R. packages

Any advice is greatly appreciated.

+4
source share
2 answers

As pointed out in the comments, the problem may be that you and your crontab are using a different installation of R.

To check if this is true, run which Rscript as you and as crontab.

If they are different (which I suspect), you can use the full path to the corresponding Rscript when you call it from crontab. For a more permanent solution, you will need to set environment variables.

+4
source

This is most likely your .libPath() parameter, so I use the Debian / Ubuntu package to use the system-wide, not the user.

To check, run both you and from the same crontab

  print(.libPaths()) print(installed.packages()) 

The difference should be clear. I think I answered almost the same question here before.

+1
source

All Articles