c++rrcpprinside

Getting Started with RInside C++


I've been an R user for about 4 years and over the past two weeks I've been developing a simple package of functions which analyse some data and plot some graphs in a way suitable for a project other members of my team and supervisor are working on and some upcoming ones too. So they've asked now if I can make it an executable file independent of the person having to know R - so it's a single .exe file with either text based menus or a simple gui.

I've been learning C++ slowly since winter and I figure RInside would be the best way to do this; use C++ to generate a .exe with R at it's heart for the amazing plotting and graphics, but it will be inside a executable my team can use. I have currently covered in C++ Variables, basic I/O with iostream, boolean and flow of control, functions, Arrays, Structures & Classes, Overloading Friends and References. I've had a look at Dirk's blog, and I have reinstalled R to C:\R\ and I have CodeBlocks and MinGW installed I've been learning C++ with. I need advice as to what precautions I should take and what things I should check/read/know before proceeding, and perhaps an advisable newb friendly way to start wading in and trying things.

Googling I find very little in the way of a tutorial or walk-through unlike Rcpp where people (for example like Hadley) have written awesome wiki's or blog-posts which I find a bit easier than jumping into the more technical documentation.


Solution

  • There is no walkthrough or tutorial -- because there are six example directories with a large number of examples.

    Look at the ones in the standard/ directory, which should take you from very simple to more advanced.

    Here is for example the simplest hello-world example, rinside_sample0.cpp:

    #include <RInside.h>                    // for the embedded R via RInside
    
    int main(int argc, char *argv[]) {
        RInside R(argc, argv);              // create an embedded R instance 
        R["txt"] = "Hello, world!\n";       // assign a char* (string) to 'txt'
        R.parseEvalQ("cat(txt)");           // eval init string, ignoring returns
        exit(0);
    }
    

    Just say 'make rinside_sample0' (or make -f Makefile.win rinside_sample0 on Windows). (Note that on Windows you need to get several DLLSs into your path etc pp -- Linux is easier that way._

    Also look at earlier questions here in the [rinside] tag.