1

My R script works as intended when I run it on its own, but when I try to run it as a cron job, it keeps failing saying

Error: RStudio not running
Execution halted 

This is the log file for the cron job.

Loading required package: methods

Attaching package: ‘lubridate’

The following object is masked from ‘package:base’:

    date

Linkging to ImageMagick 6.8.9.9
Enabled features: cairo, fontconfig, freetype, fftw, lcms, pango, rsvg, x11
Disabled features: ghostscript, webp
Loading required package: bitops

Attaching package: ‘gmailr’

The following object is masked from ‘package:lubridate’:

    date

The following object is masked from ‘package:utils’:

    history

The following objects are masked from ‘package:base’:

    body, date, labels, message

Error: RStudio not running
Execution halted```

This is my cron job set up

## cronR job
## id:   job_3284804a12afb8b01664417646b9fc7f
## tags: 
## desc: I execute things
0-59 * * * * /usr/lib/R/bin/Rscript '/home/rstudio/dev/082017_email/weekly_email.R'  >> '/home/rstudio/dev/082017_email/weekly_email.log' 2>&1

```

Harry M
  • 1,848
  • 3
  • 21
  • 37

1 Answers1

2

Sounds like you are trying to do something that can only be run in RStudio. Maybe one of you functions is trying to call a fucntion that can only be run in RStudio, for example one of the functions from here?

In that case, as suggested here, you can make the behavior of your script dependent on whether it's run in Rstudio or not. That can be achieved with the following line:

isRStudio <- Sys.getenv("RSTUDIO") == "1"

Hope this helps.

Florian
  • 24,425
  • 4
  • 49
  • 80