Rscript execution vs RSP IDE execution - Huge runtime difference

I have a user running some R code in RStudio Server Pro which completes in around 5 hours consistently. The goal though, is to automate this task. So to that end, he'll execute the same code via rscript from the command line of the server so that we can add it to a cron or third-party job scheduler. Executing the code via rscript results in a 38 hour runtime. This is on the exact same server processing the exact same data, running the exact same code. The command he is running is "/bin/Rscript /some_directory/data_harmonization/data_harm.R". Any ideas why the runtime increases by over 6x when executing from command line? Is there a better way to do this? (Caveat: this is a big job and requires a beefy server which we have. I'd try scheduling it via Connect, but that server is not up to the task.)

This kind of approach usually works fine and in general, unless you're using specific IDE features in the script, we'd expect the execution time to be more-or-less the same.

I'd start by checking that you're using the same version of R/Rscript in both places - /bin/Rscript is often just the default version of R installed on the server and not necessarily the specific version you're using in the IDE.

You'll also want to make sure that you use appropriate Linux job control features such as nohup and & to ensure that the script continues running in the background even after you've logged off.

Above and beyond that, there's not usually much else to it. If the above don't help, it might be worth adding log messages (with timestamps!) to the script, so that you can try to isolate exactly what's going on. You could even include a sessionInfo() in the log output to dump out the current R version and attached package info, just to make sure everything looks good.


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.