r-lib / callr

Call R from R
https://callr.r-lib.org/
Other
299 stars 38 forks source link

Primary R console busy as long as child process is busy #105

Closed anv42 closed 5 years ago

anv42 commented 5 years ago

Hello,

I'm trying to use callR to initiate a child process that would host a plumber API on my localhost. The idea is to free up the primary R console so that some testing can be performed on the API while it's run locally. Is it the case that the primary R console will also stay busy as long as the child process is running?

Regards, Anvaya

gaborcsardi commented 5 years ago

Which function do you mean specifically? Yes, some are synchronous, others are asynchronous.

anv42 commented 5 years ago

Here's the actual bit of code that I'm running. If I execute the below mentioned code :

callr::r( function() { pr <- plumber::plumb(file.path("/users", "xxx", "xxx", "xxx", "ApiPackage", "inst", "plumber.R")); print(pr) })

the child process finishes and prints the plumbed object to the primary R console. But when I try to run the plumbed script in the child process (as given below), since the plumber API runs on the local port until I manually stop it, the primary R console also stays busy

callr::r( function() { pr <- plumber::plumb(file.path("/users", "xxx", "xxx", "xxx", "ApiPackage", "inst", "plumber.R")); pr$run(port=8000) })

Is it possible to run the API only on a different R process and keep my primary R console free?

gaborcsardi commented 5 years ago

Yes, see r_bg() or r_process. If you need to keep sending commands to the bg process, then see r_session.

anv42 commented 5 years ago

Thanks a ton! r_bg() worked like a charm.

gaborcsardi commented 5 years ago

Yeah, I realize these functions/classes should probably be in the README.... https://github.com/r-lib/callr/issues/106