1

Background/what I've tried:

My end goal is to be able to dispatch some C++ code (a rather large physics-simulation application) from RStudio and while that C++ code is running have it repeatedly talk to an embedded R instance in order to make decisions. Once complete the C++ code would return results back to R

What is working is both parts separately. Using Rcpp I can launch the physics simulation from RStudio and have the C++ code return information back to RStudio assuming the C++ code doesn't talk to an embedded R instance. With RInside/Rcpp I was also able to get the C++ program to run and query an embedded R instance as it goes about its business.

When I try to combine the two, I get an error that an R instance is already initialized - which of course makes sense, this is the RStudio instance. I tried looking at RInside::InstancePtr(), but it doesn't look like RInside::instance_m is set by RStudio

Question: Is it possible to re-use an existing RStudio R instance as an embedded instance for use with RInside?

It seems likely that this is just not possible, that the one R instance can't be accepting input from the running C++ program while at the same time waiting for that same C++ program to return.

The reason for the above structure is that I would like R be able to dispatch many physics simulations with different parameters and aggregate those results. I would also like certain decision-making logic (the embedded R files) be able to be written in R rather than in C++ to make it easier for users. Those are what guided me to the above idea for a solution

Jay
  • 93
  • 6
  • 2
    Fair question, and I agree with your assessment: your choice of RStudio _as a run-time environment_ may preclude this as it already runs an R instance. You could run in the RStudio (shell) console instead. Or on the command-line. Or do something else out of process like Rserve with its RSclient. – Dirk Eddelbuettel Jun 24 '20 at 16:19
  • @DirkEddelbuettel By RStudio (shell) console, do you mean the (bash) shell within RStudio, correct? And on the command-line do you mean typing `R` and using the environment there? Both seem to have the same problem as RStudio, they output "R is already initialized" and then the R process crashes. Thanks for your input though, I will look into Rserve and RSclient – Jay Jun 24 '20 at 16:42
  • Yes exaxtly. Command-line commonly refers to shell session in `bash` or `zsh` or ... which is also what you get on most computers before you launch other commands. – Dirk Eddelbuettel Jun 24 '20 at 17:13

0 Answers0