Hello, I need to include C (or C++)-Code in R. I'm searching for a tutorial, how to do this. It is only a very small algorith (one function). Using google, I read somethig about including dll-Files and so on (on windows). Is there no possibility to include a C-File directly?!? -- View this message in context: http://www.nabble.com/C-Code-in-R-%28running-Windows%29-t1205196.html#a3182004 Sent from the R help forum at Nabble.com.
The simplest way to add C (C++) code in R, that I know is by creating a package ( even if you are not planning on distributing it). See 'Writing R Extensions' manual (http://cran.r-project.org/manuals.html) for details. Download source codes of packages for more examples, many of them will have .c files. See also FAQ http://cran.r-project.org/bin/windows/base/rw-FAQ.html#Building-from-Sou rce . Jarek Tuszynski -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of K.A. Sent: Wednesday, March 01, 2006 7:14 AM To: r-help at stat.math.ethz.ch Subject: [R] C-Code in R (running Windows) Hello, I need to include C (or C++)-Code in R. I'm searching for a tutorial, how to do this. It is only a very small algorith (one function). Using google, I read somethig about including dll-Files and so on (on windows). Is there no possibility to include a C-File directly?!? -- View this message in context: http://www.nabble.com/C-Code-in-R-%28running-Windows%29-t1205196.html#a3 182004 Sent from the R help forum at Nabble.com. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
The simplest interface is to use .C() in R to call the C function. The details (with examples) are in the Writing R Extensions manual that comes with every version of R. To compile and load the .dll/.so into R, do: - Type R CMD SHLIB file1.c file2.c (at the command prompt, not the R prompt) -...start up R in that directory - Type dyn.load("file1") - You can now use .C() to call the function Andy From: K.A.> > Hello, > > I need to include C (or C++)-Code in R. I'm searching for a > tutorial, how to > do this. It is only a very small algorith (one function). > Using google, I > read somethig about including dll-Files and so on (on windows). > > Is there no possibility to include a C-File directly?!? > -- > View this message in context: > http://www.nabble.com/C-Code-in-R-%28running-Windows%29-t1205196.html#a3182004 Sent from the R help forum at Nabble.com. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html