Re: [Rd] How to call R from C
Thank you! I tried to build a C code below, and I got a error message. Thank you for your help in advance. C code #include embeddedRCall.h int main(int argc, char *argv[]) { eval_R_command(print, argc, argv); return(0); } = error message Configuration: Rtest - Win32 Debug Compiling... Rtest.c Linking... Rtest.obj : error LNK2001: unresolved external symbol _eval_R_command Debug/Rtest.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. Rtest.exe - 2 error(s), 0 warning(s) -- View this message in context: http://r.789695.n4.nabble.com/How-to-call-R-from-C-tp3053943p3054977.html Sent from the R devel mailing list archive at Nabble.com. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to call R from C
On Tue, 23 Nov 2010, Wonjae Lee wrote: Thank you! I tried to build a C code below, and I got a error message. How?: you have not shown us the commands you used. At a guess you are on Windows and didn't tell us (see the posting quide) using MSVC (not supported but may work -- just don't ask us for help) not linking against R.dll. There are examples in the tests/Embedding directory of the R sources -- and they do work on Windows. Thank you for your help in advance. C code #include embeddedRCall.h int main(int argc, char *argv[]) { eval_R_command(print, argc, argv); return(0); } = error message Configuration: Rtest - Win32 Debug Compiling... Rtest.c Linking... Rtest.obj : error LNK2001: unresolved external symbol _eval_R_command Debug/Rtest.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. Rtest.exe - 2 error(s), 0 warning(s) -- View this message in context: http://r.789695.n4.nabble.com/How-to-call-R-from-C-tp3053943p3054977.html Sent from the R devel mailing list archive at Nabble.com. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Brian D. Ripley, rip...@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, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] How to call R from C
Hi all! I read R Extensions manual. But still I am not sure how to call R functions from C. Would any of you give me a sample C code to show how to call R functions - for instance, time series functions - from C in the embedded way of C code? [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to call R from C
On Tue, 23 Nov 2010 01:24:04 +0900, 이원재wjlee2...@naver.com wrote: Hi all! I read R Extensions manual. But still I am not sure how to call R functions from C. Would any of you give me a sample C code to show how to call R functions - for instance, time series functions - from C in the embedded way of C code? Look at package xts, among many others, for examples (xts is one of the time series classes that makes extensive use of C code). - Brian -- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to call R from C
Le 22/11/10 17:24, 이원재 a écrit : Hi all! I read R Extensions manual. But still I am not sure how to call R functions from C. Would any of you give me a sample C code to show how to call R functions - for instance, time series functions - from C in the embedded way of C code? As Brian said, there are plenty of examples to follow. The basic idea is to create a call and evaluate it. txt - ' #include R.h #include Rdefines.h SEXP callrnorm(){ SEXP call = PROTECT( lang2( install( rnorm), ScalarInteger(10) ) ) ; SEXP res = PROTECT( eval( call, R_GlobalEnv ) ) ; UNPROTECT(2) ; return res ; } ' writeLines( txt, test.c ) system( R CMD SHLIB test.c ) dyn.load( test.so ) .Call( callrnorm ) or using the inline package : require(inline) fx - cfunction( , ' SEXP call = PROTECT( lang2( install( rnorm), ScalarInteger(10) ) ) ; SEXP res = PROTECT( eval( call, R_GlobalEnv ) ) ; UNPROTECT(2) ; return res ; ' , verbose = TRUE) fx() And now for the Rcpp plug ;-) calling R functions is dramatically easy with Rcpp with the Rcpp::Function class. require(inline) fx - cxxfunction( , ' // grab the function Function rnorm(rnorm) ; // call it return rnorm(10, _[sd] = 10) ; ' , plugin = Rcpp ) fx() Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9VOd3l : ZAT! 2010 |- http://bit.ly/c6DzuX : Impressionnism with R `- http://bit.ly/czHPM7 : Rcpp Google tech talk on youtube __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to call R from C
On Tue, 23 Nov 2010 01:24:04 +0900, 이원재wjlee2...@naver.com wrote: Hi all! I read R Extensions manual. But still I am not sure how to call R functions from C. Would any of you give me a sample C code to show how to call R functions - for instance, time series functions - from C in the embedded way of C code? Dirk indicates that I may have misunderstood your question. Perhaps this will help. http://quantitative-ecology.blogspot.com/2008/11/call-c-from-r-and-r-from-c.html If you need further help, please provide a minimal self-contained example of what you're trying to do. - Brian -- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel