From chuck at sharpsteen.net  Fri Apr 22 04:02:27 2011
From: chuck at sharpsteen.net (Sharpie)
Date: Thu, 21 Apr 2011 19:02:27 -0700 (PDT)
Subject: [Rd] FW: [Rcpp-devel] Question on 5.6 Interfacing C++ code
In-Reply-To: <C9D5C7C2.3DD0%sean.mcguffee@gmail.com>
References: <C9D47520.3D72%sean.mcguffee@gmail.com> <4DB011F3.80603@gmail.com>
	<19888.6774.24607.71449@max.nulle.part>
	<C9D5C297.3DCA%sean.mcguffee@gmail.com>
	<BANLkTimOXKGN2yUvxF_+-bKZgXQMfOBHHg@mail.gmail.com>
	<C9D5C7C2.3DD0%sean.mcguffee@gmail.com>
Message-ID: <1303437747451-3467221.post@n4.nabble.com>


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.



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