How to set up Eclipse + StatET + Rcpp on Windows
Asked Answered
L

2

8

When I came to know that I can create a R package with C++ using Rcpp, I was excited about it and eager to know development environment for it. And thanks to Fell Stat Blog, I could quickly establish a great environment using Eclipse with StatET, its plugin for R, to use Rcpp and RInside (another package for embedding R into your C++ application) on Windows.

Since the blog was, however, based on OS X, several things required trial & error (& almost give-up) to adjust for Windows - it took me 6 hours of my leisure time. For example, you need to install Rtools to be able to compile C/C++ using R CMD statements and Miktex to convert your Rd files to pdf file. In addition, build settings are different from OS X.

In order to save others from possible trial & error period I've experienced, I made this wiki on Eclipse + StatET + Rcpp on Windows. Feel free to make comment or another answer. Otherwise, enjoy this great open source environment for analytical software development you can get.

UPDATE (late 2016): Few years ago, I changed IDE for R from Eclipse to RStudio and I recommend it for everyone using R and Rcpp.

Locular answered 14/10, 2012 at 21:4 Comment(2)
I am not sure if posting a question and its answer is the best way about this. Maybe you can contribute this as a vignette to the package instead?Inconstant
I hoped this kind of wiki while working on it. I don't mind contributing to Rcpp vignette, but as a lazy programmer seeking help, I would like this Q&A setting better though.Locular
L
3

For this wiki, I will proceed my talk based on the latest version of R, R 2.15.1 and this is the list of steps you need to follow.

  1. If you have already installed R in your Windows system, make sure its path does not include space such as "C:\Program Files\R\R-2.15.1". If so, there is nothing you can do but reinstall your R system to a directory such as "C:\R\R-2.15.1". If you don't do that, Rcpp or RInside will not work on your system.

  2. Install Rtools (Rtools2.15.1 in this case) This installer includes basic tools to run R CMD and related things and gcc compiler. I installed this into "C:\Rtools"

  3. (Optional) You can install MikTex to automatically generate pdf file from your Rd files when R CMD check executed. Make sure <Miktext installation directory>\miktex\bin is in your system path.

  4. Include following directories into your system path. This is important. Otherwise, most of them here will not work.

    C:\Rtools\bin; C:\Rtools\gcc-4.6.3\bin; C:\R\R-2.15.1\bin\i386;

  5. If you don't have Eclipse yet, please install it with CDT If you have it already, make sure you have installed CDT plugin.

  6. Now it's time to install an Eclipse plugin for R, StatET As the web site suggested, I used http://download.walware.de/eclipse-3.8 to install it. After that, ran R windows and installed Rj install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-1.1") After that, you are done with installing StatET. In Eclipse, follow Cheatsheet of StatET to make yourself familiar with the environment. Especially, create R environment, R console configuration, external configuration for R CMD check, build, install so you can run R and its CMD in Eclipse.

  7. It's time to install Rcpp and RInside. As Fell Stat recommended, I used following in R console in Eclipse to do that. install.packages(c("Rcpp","RInside"),type="source") This will get source of Rcpp and RInside from internet and compile them before installing them. If you get any error message here, it's good time to check you followed everything I described above. In my case, I got some when I didn't set system path right or when my R path included space.

  8. Now it's time to examine the environment with a test project. For this, I recommend you read step 4, 5, 6, 7 of Fell Stat Blog. One thing I recommend is that when you create a sample project, use

    Rcpp.package.skeleton("MyCppPackage", module=TRUE)

    That way, you would experience power of Rcpp with Rcpp modules.

  9. As I said, in #7, some settings are different from OS X on Windows. I will just display my setting here on images. Here, I didn't set directories for RInside, but I hope you can easily figure this out from Rcpp setup.

enter image description here enter image description here enter image description here

Hope this helps. Enjoy.

Locular answered 14/10, 2012 at 21:4 Comment(1)
I want to use this to debug inside a compiled c++ code which is called inside R function. I am using R package called mirtCAT. there is a function in this package called mirtCAT. They have used many c++ functions inside this R function. Will I be able to debug the way I want using Eclipse + Statet? If yes, how?Negotiable
D
0

You can use a packaged installation of Eclipse and R called Architect from Openanalytics.

Distal answered 29/4, 2014 at 19:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.