Beside the possible argumentation that with an API elegance and convenience might sometimes be superior to necessity, the suggested pattern ("every program, including R itself, keeping its own flag") does no work too well when the nested embedding of R is involved. A concrete example is: ``` $ R -q> library('rPython'); python.exec('import rpy2.robjects')R is already initialized ``` https://bitbucket.org/rpy2/rpy2/issue/278/r-in-python-via-rpy2-in-r-via-rpython#comment-17843761 2015-05-03 18:12 GMT-04:00 Duncan Murdoch <murdoch.duncan at gmail.com>:> On 03/05/2015 4:34 PM, Laurent Gautier wrote: > > Hi, > > > > There appear to be no way to check whether R has already been > initialized. > > > > Could a function like "Rf_isinitialized" be added to the API ? > > > > Surely any program that needs to know that could keep its own flag. > You'll need to give a much longer argument about why this is necessary > for what you're doing. > > Duncan Murdoch > >[[alternative HTML version deleted]]
On 03/05/2015 7:02 PM, Laurent Gautier wrote:> Beside the possible argumentation that with an API elegance and > convenience might sometimes be superior to necessity, the suggested > pattern ("every program, including R itself, keeping its own flag") does > no work too well when the nested embedding of R is involved. > > A concrete example is: > ``` > $ R -q >> library('rPython'); python.exec('import rpy2.robjects') > R is already initialized > ```I don't know rPython at all, but surely this is an rPython bug. When the package is loaded by "library('rPython')", R is obviously initialized. You don't need to query it to ask that. The standard R front-ends don't need a flag to know if it is initialized. They initialize, then go into the read-eval-print loop. If they are in that loop, R is initialized. If it failed to initialize, they would never get to that loop. Other front-ends may do other things besides run R, so they do need to know if it is initialized, but surely they can keep a flag telling them whether they've succeeded in initializing it. Duncan Murdoch
rPython appears to provide an interface from R to Python by embedding Python and I'd think that it can safely assume that R has been initialized, but might not be the point here. The issue is that a Python package embedding itself R (here rpy2) appears to have no way to know that earlier in the life of the process R was initialized. 2015-05-03 19:48 GMT-04:00 Duncan Murdoch <murdoch.duncan at gmail.com>:> On 03/05/2015 7:02 PM, Laurent Gautier wrote: > > Beside the possible argumentation that with an API elegance and > > convenience might sometimes be superior to necessity, the suggested > > pattern ("every program, including R itself, keeping its own flag") does > > no work too well when the nested embedding of R is involved. > > > > A concrete example is: > > ``` > > $ R -q > >> library('rPython'); python.exec('import rpy2.robjects') > > R is already initialized > > ``` > > I don't know rPython at all, but surely this is an rPython bug. When > the package is loaded by "library('rPython')", R is obviously > initialized. You don't need to query it to ask that. > > The standard R front-ends don't need a flag to know if it is > initialized. They initialize, then go into the read-eval-print loop. > If they are in that loop, R is initialized. If it failed to initialize, > they would never get to that loop. > > Other front-ends may do other things besides run R, so they do need to > know if it is initialized, but surely they can keep a flag telling them > whether they've succeeded in initializing it. > > Duncan Murdoch >[[alternative HTML version deleted]]
Reasonably Related Threads
- C-API: check whether R has been initialized ?
- C-API: check whether R has been initialized ?
- C-API: check whether R has been initialized ?
- Issue when calling deparse(substitute(x)) from C with "anonymous" R vectors ?
- C-API: check whether R has been initialized ?