9

I have a script in R that is frequently called during the day (by other scripts). I call R in a terminal using

Rscript code.R

I notice it takes a lot of time to load packages and set up R.

Is it possible to run R as a background service which I hit using a port or something?

Dason
  • 60,663
  • 9
  • 131
  • 148
Anubhav Dikshit
  • 1,729
  • 6
  • 25
  • 48

2 Answers2

8

Yes, look into RServe which has been available for over a dozen years for this reason. There are a couple of fairly high profile applications too.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • +1. It’s worth noting that RServe is of course not necessary — one can simply use Rscript/littler/whatever to execute a normal R scrip that sets up its own TCP/IP listener. – Konrad Rudolph Jan 10 '17 at 16:00
  • True -- and things like [rzmq](https://cran.r-project.org/package=rzmq) even make to possible to 'serve' easily. [RServe](https://rforge.net/Rserve/) is still more general in offering the full REPL. – Dirk Eddelbuettel Jan 10 '17 at 16:03
  • @DirkEddelbuettel Would it be possible to load up trained models (.RDA) and and libraries also? – Anubhav Dikshit Jan 11 '17 at 06:01
  • Yes, as there are essentially no limits to what R scripts you can load at startup of the session started by Rserve. – Dirk Eddelbuettel Jan 11 '17 at 11:16
0

You can check out this add-in for Rstudio, it is not a port like solution but maybe it can help you https://github.com/bnosac/taskscheduleR

Fernando Macedo
  • 355
  • 3
  • 7