Re: [Rd] FW: [Rcpp-devel] Question on 5.6 Interfacing C++ code

From: Sharpie <chuck_at_sharpsteen.net>
Date: Thu, 21 Apr 2011 19:02:27 -0700 (PDT)

smcguffee wrote:
>
> You are right, I looked and I did find the R source code. However, it's
> largely written in R! I mean, I don't know how to trace the R code where
> INSTALL is recognized and follow it to a c or c++ level command. For
> example
> these are hits in .R files, not c files, and I don't know how to connect
>
> ...
>
> If you could point me to the functions that are called a c or c++ level,
> I'd
> love to see what R is doing for myself.
> Thanks!
> Sean
>

Hi Sean!

Along with many other people in this thread, I would strongly recommend a top-down approach to this. Build a package, stick some stuff in the src folder, run R CMD INSTALL on it and see what happens. The reason I recommend this approach is that it lets you focus on writing a package that does something useful rather than the nuts and bolts of cross platform compilation and installation. R CMD INSTALL takes care of this for you automagically and it is very good at what it does.

I wrote a post some time back about building an example package from scratch that contains C code:

http://r.789695.n4.nabble.com/Writing-own-simulation-function-in-C-td1580190.html#a1580423

It begins with the using the package.skeleton() function to kickstart things, discusses how to make sure the compiled code is dynamically loaded when a user runs library(your_package) and even discusses how to call R functions from inside of C functions and vice-versa. The example code is still available and I'm sure it could be generalized to C++ quite easily. There are also some other responses in that thread that offer useful advice.

At the beginning it is just best to treat R CMD INSTALL as a magical unicorn that gets you where you need to go:

http://abstrusegoose.com/120
(keep clicking the images to get the full story)

If you are absolutely, positively dying to know what really happens... well, the relative files in the R source are `src/library/tools/R/install.R` and `src/library/tools/R/build.R`.

But seriously. Magical unicorn. Takes care of the hard stuff so you can build awesome packages.

Hope this helps!

-Charlie



Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering Humboldt State University
--
View this message in context: http://r.789695.n4.nabble.com/FW-Rcpp-devel-Question-on-5-6-Interfacing-C-code-tp3465257p3467221.html
Sent from the R devel mailing list archive at Nabble.com.

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri 22 Apr 2011 - 02:05:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 22 Apr 2011 - 18:40:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive