[R] Embedded R: Test if initialized

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Wed Jun 16 23:20:11 CEST 2021

I believe this is the wrong list for this post. See the posting guide,
linked below, for one that is more appropriate.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Wed, Jun 16, 2021 at 12:51 PM Matthias Gondan <matthias-gondan using gmx.de>

> Dear R friends,
> I am currently trying to write a piece of C code that uses „embedded R“,
> and for specific reasons*, I cannot keep track if R already has been
> initialized. So the code snippet looks like this:
> LibExtern char *R_TempDir;
> if(R_TempDir == NULL)
>     …throw exception R not initialized…
> I have seen that the source code of Rf_initialize_R itself checks if it is
> ivoked twice (num_initialized), but this latter flag does not seem to
> accessible, or is it?
> int Rf_initialize_R(int ac, char **av)
> {
>     int i, ioff = 1, j;
>     Rboolean useX11 = TRUE, useTk = FALSE;
>     char *p, msg[1024], cmdlines[10000], **avv;
>     structRstart rstart;
>     Rstart Rp = &rstart;
>     Rboolean force_interactive = FALSE;
>     if (num_initialized++) {
>         fprintf(stderr, "%s", "R is already initialized\n");
>         exit(1);
>     }
> Is the test of the TempDir a good substitute, or should I choose another
> solution? Having said this, it may be a good idea to expose a function
> Rf_R_initialized that performs such a test.
> Thank you for your consideration.
> Best regards,
> Matthias
> *The use case is an R library that connects to swi-prolog and allows the
> „embedded“ swi-prolog to establish the reverse connection to R. In that
> case, i.e., R -> Prolog -> R, I do not want to initialize R a second time.
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]

More information about the R-help mailing list