[Rd] Question on parsing R code from C

KR krunal.rao78 at gmail.com
Fri Nov 11 00:24:10 CET 2011

First of all thanks a lot to you both for all the replies, they have been of 
great help to me!

I got the basic embedding running, however I still have some issues to solve in 
order to complete the interface to R I am working on:

1. I initialize with Rf_initEmbeddR().
- Is there a way to have more than one R "state" (per single thread)? Or is 
everything necessarily global?
- I also read somewhere that the fpu settings may be touched. Is there a way to 
make sure that this is not the case? Is this related to fpu_setup()?

2. I create a string and parse it via Rf_mkString() and R_parseVector() (yes I 
protect/un-protect the SEXPs).
- Is it possible to obtain the precise error message, like "unexpected symbol 
in..." (as would be reported by R.exe) in case of error as a const char* string?
- If I pass a wrongly escaped string (for instance 'ggsave("C:\gtest.png")', 
please notice the missing \) I get on stderr: Error '\g' is an unrecognized 
escape and I get a crash. This does not happen if for instance i try to parse 
'rnorm(10a10)' in which case I get the error flag and the NULL ptr return. I 
suspect I need to initialize something / set a callback to avoid this but I am 
not sure...

3. I eval with R_tryEvalSilent().
- Again, is it possible to obtain the precise error message in case of 
evaluation error as would be reported from R.exe?

4. Regarding the returned result of evaluation.
- What is the correct way to obtain a const char* string representing the result 
as would be "printed" in the R shell by executing a command (for instance 
"summary(c(1,2,3))") ?
- Why is the return type (as reported from typeof in R and TYPEOF in C) of 
"summary(c(1,2,3))" a double?

Any help / feedback on these issues would be greatly appreciated.

Thanks again.

More information about the R-devel mailing list