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