Hello, I am very new to R but my question is with respect to the C API for working with an embedded R console. I have been able to start and stop an embedded R console from within a C program as well as use the API to execute commands in it. I am seeking a mechanism to individually send native R commands to an embedded console and then consume the output of these commands. Specifically, I cannot send a set of commands to the embedded console and then consume all of the output after the execution completes. I have unsuccessfully attempted to assign values to the ptr_R_ReadConsole and ptr_R_WriteConsole function pointers defined in Rinterface.h but do not know if this is a valid approach. I am working in Ubuntu 10.04 and thus the Windows example at the following address is not applicable. http://cran.r-project.org/doc/manuals/R-exts.html#Calling-R_002edll-directly Does anyone on this list have experience or an example of communicating with an embedded R console using native R commands and consuming the output one command at a time in a "Unix-alike" environment? Thank you, Mike Sonsini
Controlling stdin and stdout in an embedded R instance
7 messages · Mike Sonsini, oliver, Simon Urbanek +3 more
Hello, I'm new in exploring R-internals, and also did not explored embedding R into C. I did some C-extensions for packages so far. Nevertheless I can give you a hint, which might be helpful; the example which you linked to, uses R.dll. DLL means: Dynamic linked library. On Unix and Linux the aequivalent is shared libraries, or also dynamic linked libraries; another term that is used here is "dynamic linking loader", which provides the possibilities to "load" those libraries, which means, make them available in your application. To use a shared library on Unix/Linux you can use the functions dlopen() dlerror() dlsym() dlclose() The manpages will explain you the details. Hope that helps. Ciao, Oliver
Mike, there are many examples of embedding R, one of them is rJava/JRI and you can see how to initialize R with custom callbacks at http://svn.rforge.net/org/trunk/rosuda/JRI/src/Rinit.c Cheers, Simon
On Jun 16, 2011, at 6:47 PM, Mike Sonsini wrote:
Hello, I am very new to R but my question is with respect to the C API for working with an embedded R console. I have been able to start and stop an embedded R console from within a C program as well as use the API to execute commands in it. I am seeking a mechanism to individually send native R commands to an embedded console and then consume the output of these commands. Specifically, I cannot send a set of commands to the embedded console and then consume all of the output after the execution completes. I have unsuccessfully attempted to assign values to the ptr_R_ReadConsole and ptr_R_WriteConsole function pointers defined in Rinterface.h but do not know if this is a valid approach. I am working in Ubuntu 10.04 and thus the Windows example at the following address is not applicable. http://cran.r-project.org/doc/manuals/R-exts.html#Calling-R_002edll-directly Does anyone on this list have experience or an example of communicating with an embedded R console using native R commands and consuming the output one command at a time in a "Unix-alike" environment? Thank you, Mike Sonsini
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
On 16 June 2011 at 18:47, Mike Sonsini wrote:
| Hello, | | I am very new to R but my question is with respect to the C API for | working with an embedded R console. I have been able to start and stop | an embedded R console from within a C program as well as use the API to | execute commands in it. I am seeking a mechanism to individually send | native R commands to an embedded console and then consume the output of | these commands. Specifically, I cannot send a set of commands to the | embedded console and then consume all of the output after the execution | completes. I have unsuccessfully attempted to assign values to the | ptr_R_ReadConsole and ptr_R_WriteConsole function pointers defined in | Rinterface.h but do not know if this is a valid approach. I am working | in Ubuntu 10.04 and thus the Windows example at the following address is | not applicable. | | http://cran.r-project.org/doc/manuals/R-exts.html#Calling-R_002edll-directly | | Does anyone on this list have experience or an example of communicating | with an embedded R console using native R commands and consuming the | output one command at a time in a "Unix-alike" environment? Let me see if I understood this correctly: - you have managed to embed R in your own application - you now want to control the embedded R instance and for the latter you want to use stdin and stdout? Why not use R commands and consuming R output? Examples are e.g. - littler (available in Ubuntu) which sends R commands line by line to R; implemented in plain C. Commands can come from the command-line, from a script or from stdin: R still sees them line by line in REPL fashion. - RInside which builds on top of the littler experience and the Rcpp API (Rcpp is also in Ubuntu) to embed R via a much nicer C++ abstraction which, coupled with Rcpp, gives you real easy communication via full blown R objects accessible from C++. There are well over a dozen examples in the RInside sources Hope this helps, Dirk
Gauss once played himself in a zero-sum game and won $50.
-- #11 at http://www.gaussfacts.com
4 days later
Thank you, this example helped. Mike Sonsini
On 6/17/2011 10:29 AM, Simon Urbanek wrote:
Mike, there are many examples of embedding R, one of them is rJava/JRI and you can see how to initialize R with custom callbacks at http://svn.rforge.net/org/trunk/rosuda/JRI/src/Rinit.c Cheers, Simon
Is there a quick way of checking the R manuals built from the .texi files in ../doc/manual without building the rest of R?
Going from a vanilla checkout, some included files are missing (eg version.texi) and created by the makefiles, so it looks like the complete make script needs to be run at least once ... and then one has a number of make-generated changes to one's R sources to worry about in any subsequent diff.
Is the only route to export the svn copy, build from the exported copy and then use texinfo to check the manual pages using the make-built includes and rules?
Steve Ellison
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
On Wed, 22 Jun 2011, Stephen Ellison wrote:
Is there a quick way of checking the R manuals built from the .texi files in ../doc/manual without building the rest of R?
What does 'check' mean?
Going from a vanilla checkout, some included files are missing (eg version.texi) and created by the makefiles, so it looks like the complete make script needs to be run at least once ... and then one has a number of make-generated changes to one's R sources to worry about in any subsequent diff.
You haven't told us your OS (pace the posting guide). On all systems the first step is to run configure (but that has already been done for you on Windows, but you do need to create MkRules from MkRules.local). Again except on Windows, we recommend working in a build directory other than the sources. Even on Windows there will be *no* 'make-generated changes to one's R sources': no files are changed but some are generated. make distclean will clean up ..
Is the only route to export the svn copy, build from the exported copy and then use texinfo to check the manual pages using the make-built includes and rules?
Possibly, depending on the meaning of 'check'. R-core (as the only people changing these manuals) also need to use a pdflatex system, to check that the PDF version can be made as the manuals have PDF-specific (and HTML-specific) sections.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595