Question on parsing R code from C
On Nov 8, 2011, at 2:42 PM, KR wrote:
Hi all, I am facing the necessity to parse R code from C-side. As a first approximation the goal would be a re-implementation of the R shell (not Rgui). I read the document at http://cran.r-project.org/doc/manuals/R-exts.html section 5.12, and the related source code example. I have some questions: 1. I need to declare the types and function signatures that I am going to use for this task without having to actually include the R headers. Can I safely declare SEXP according to the following ? typedef struct SEXP *unknwn_handle;
I'm not sure I understand this really - it doesn't define SEXP. I would expect something like typedef void *SEXP; Which may work for declarations. Note, however, that for the actual code you'll need to include the headers anyway.
More in general, is there a reference document for the C API (listing function signatures, and type definitions) ?
http://r.research.att.com/man/R-exts.html is the documentation and the headers (Rinternals.h mainly) is the canonical reference.
2. If the parsed R code of the working implementation contain commands like plot(), will the opportune windows pop-up as if I were using the R shell (on both windows and unix systems) ?
It depends on your settings - plot() uses whatever graphics device you tell it to use, so plot() doesn't decide about that. If you use the proper interactive graphics device *and* make sure you're serving the REPL then it may work. Beware of interactions with your other parts, though, since you are responsible for ensuring that it works.
3. What initialization do I need to perform to be in exactly the same starting state as if I had executed the R shell with the --vanilla option?
It depends on the OS and the way you are initializing R. In the simple case pass the "--vanilla" as the argument when initializing R. Please read the section about embedding, it has examples. Also see the other R GUIs to understand the complexities involved. BTW: you subject has absolutely nothing to do with your question - your'e asking about embedding R ;) Cheers, Simon
Any help or feedback is appreciated. Thank you. Kind regard
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel