Run cron job within RStudio


I am trying to schedule a cron job via RStudio on EC2 instance.
When I use a basic script with very basic functions it works fine.
But when I want to schedule a script that contains R functions from specfic R packages, the scripts fails.

My cron looks like this:

36 * * * * /home/user1/Test_for_Cron.R

After the script is launched, I receive an email from Cron Daemon specifying something like:

Error in R_function :
could not find function R_function
Execution halted

From what I found, it seems I have to specify that I want to run the script within RStudio or that I want to "source" it.
I have the feeling the answer might be in the combination of these 3 posts below but I am not finding the solution after testing out some suggestions:

Help much appreciated !

I personally don't have experience with cronr but it's a curious error.

Any way you could create a reproducible example of this error with an example .R script and cron script?

I actually found it, I just needed to install the package before... Thanks !

1 Like

If your question's been answered (even if by you), would you mind choosing a solution? (See FAQ below for how).

Having questions checked as resolved makes it a bit easier to navigate the site visually and see which threads still need help.


1 Like