R 2.12.0 and Eclipse with StatET installation


A while back I outlined the setup process for running R under the Eclipse integrated development environment with the help of WalWare.de’s StatET plugin for Eclipse, in Windows 7. This post is an update on that procedure for the newer versions of each of the programs now available.

Specifically, this information pertains to an installation of Eclipse 3.6 (Helios), StatET version 0.9.1.b201011060900E36sw, and R 2.12.0, under Windows 7 64-bit (circa December 2010). The process for making R work within Eclipse has become a bit more involved, but the procedure outlined here works for me with both 32-bit and 64-bit versions of Eclipse and R. These steps are all outlined on the WalWare.de site, and I merely recreate them here to hopefully make it easier for beginning users. All of the software here is freely available, and Mac/Linux analogs exist, but these instructions are specific to Windows.

Begin by downloading the current version of R for Windows. In the old days there were separate files for 32-bit or 64-bit R for Windows, but as of R version 2.12.0 the two versions are packaged together. If you install R 2.12.0 or later and look in the \bin folder, you will see two directories, i386 and x64. The i386 folder contains files for the 32-bit version of R, and the x64 folder contains files for the 64-bit version of R. Note that you can only run the 64-bit version of R on a 64-bit operating system, otherwise you are restricted to the 32-bit version, which is perfectly fine for almost everyone. If you have been running R under Eclipse with StatET prior to the release of R 2.12, you will have to upgrade your version of StatET to deal with the new directory structure of R 2.12.

Anyhow, after you have run the R installer (R-2.12.0-win.exe in this case), you need to install the rJava package before any further setup. Click your way into the R\bin\i386 folder and you will find a file called Rgui.exe. Run that file. In the R terminal window that opens, type install.packages("rJava") and hit Return. R will open a window and have you choose a mirror to download the package from, and then R will install the rJava package. You can close the R terminal at this point (hint: q() quits the session). If you look in your R\library folder you should now find a rJava folder.

Install the rJava package.

The next step is to install the rj package from WalWare.de. At the walware.de site you will find the rj package on the downloads page partway down the page, with a filename like rj-0.5.0-5.tar.gz. Download the file to your computer. I recommend dragging it to your R\bin\i386 folder for next step.

To uncompress and install the rj package, we’ll have to use the Windows command line. To open a windows command terminal in Windows 7, it’s easiest to just hit the Windows key on your keyboard and type command into the search box that pops up in the Start menu. Hit return and a command window should open.

In the Windows command terminal, you’ll now need to navigate to the R\bin\x64 directory where you just placed the rj-0.5.0-5.tar.gz file you downloaded. Recall that the cd command allows you to specify what directory you want to work in. In my case, the terminal starts in C:\Users\Luke, which is not where my R installation lives. I keep my R installation on my D: hard drive. So I start by typing d: at the command prompt and hitting return. The command prompt changes to read D:\>. I can then type cd D:\Eclipse\R_test\bin\i386 which is where my particular installation lives (the example image below shows me doing this in the x64 folder, but all that matters is you carry out the next command in the i386 or x86_64 folder where you put the rj file). Typing dir should show you the contents of the directory, where you should find several R files, most importantly the rj-0.5.0-5.tar.gz file and R.exe. We will call R.exe from the command line and use it to unpack the rj file and install the rj library. At the command prompt, type R CMD INSTALL --no-test-load rj_0.5.0-5.tar.gz Please note that as the rj file is updated in the future with a new version number, you will need to enter the appropriate current file name. The command terminal should show the progress of the installation. If you are not on a 64-bit operating system, you must carry out this step in the R\bin\i386 folder.

Install the rj package from the Windows command prompt.

If this is successful, you should be able to look in your R\library folder and find a new rj folder, right next to the rJava library you installed earlier.

Both the rj and rJava libraries successfully installed in the R library folder.

At this point you can run Eclipse and begin the StatET installation. Download a version of Eclipse from the website. These instructions should work for both Eclipse 3.5 and 3.6, both 32-bit and 64-bit versions (you can only run the 64-bit version on a 64-bit operating system). Unzip the files, then find and run the eclipse.exe file.

On your first launch of Eclipse, you’ll get a popup window asking you to specify a workspace directory, which is where Eclipse will store its preference files (and possibly your R files depending on your setup).

Select a workspace folder for Eclipse to store data in. Check the box to make this default on every launch of Eclipse.

The Welcome screen of Eclipse will appear next. Click on the Workbench icon in the upper right of the window to bring up the main Eclipse window.

Hit the Workbench button in the upper right to get to the main Eclipse window.

The next step is to download and install the StatET plugin files from the WalWare site. Go t0 Help>Install New Software. In the window that opens, you will enter the address for the Walware repository appropriate for your version of Eclipse. The list of repository addresses is given here under the Installation & Update section. If you are running Eclipse 3.5 (Galileo), the use the address for Eclipse 3.5, and if you run Eclipse 3.6 (Helios) use the Eclipse 3.6 address. Enter the address in the “Work with” field in the Eclipse window and hit “Add…”.

Enter the appropriate WalWare repository address in the Work with field.

Eclipse will then query the WalWare site and get the appropriate plugins. These will be presented to you in the central window. I recommend you hit Select All and hit Next to step through the download and installation. After the installation, Eclipse will prompt you to restart (Eclipse only, this doesn’t require a restart of your computer).

Just go ahead and select all of the plug-ins available in the window. Hit Next to continue the installation.

When Eclipse reboots, you should be greeted with a new Welcome screen that includes a choice to help configure a R console.

Click on the Configure and Launch an R Console item to launch a guide for setting up R in Eclipse.

We start by specifying the “connector” between Eclipse and R. Go to the Window>Preferences menu item in the main Eclipse window. In the Preferences window that opens, find the StatET entry in the list on the left. Click on StatET to open it, and go to StatET>Run/Debug/R Interaction. When you click on R Interaction, it should bring up a panel in the Preference window. Make sure that the “New Console inside Eclipse” is selected from the menu. Click Apply.

Make sure New Console inside Eclipse is selected.

Next, in the list of items on the left of the Preferences window, choose StatET>Run/Debug>R Environments. In the new panel that opens on the right, click on the Add… button. A new window will appear where you will specify to Eclipse where all of the R program files live.

R environment configuration window

Before you do anything else, enter a descriptive name in the Name field at the top of the window. In this case I called my environment R-2.12.0_x64_test. This will allow me to distinguish it from a 32-bit environment I might make later, or an environment for a future updated version of R like R-2.13.0.

Enter a descriptive name for this environment in the Name field. Then click the + button to tell Eclipse where R is installed.

After naming your environment, click on the + button next to the Location field. Choose Browse filesystem, and go to the directory that contains your R program files. Choose the top-level R folder, not the R\bin or R\library folder.

The choice for the Architecture depends on which version of R you plan to run. Most people will probably want to run the 32-bit version, but others may want the 64-bit version. If you want to run the 32-bit version, choose “i386” from the white menu next to Architecture, and choose “32-bit” in the gray menu next to that. In my case, I’m going to run the 64-bit version, so I chose “x86-64” and “64-bit” from the two architecture menus. In either case, after you make your selections, hit the “Detect Default Properties/Settings” button. In most instances, this should automatically find the various components of the R program and display them in the lower half of the Environment Configuration window.

Choose the appropriate architecture for the version of R you plan to run, and then hit Detect Default Properties/Settings.

If the detection works, you can hit OK and return to the Preferences window where the list of R Environments is displayed. You must now click on the R environment you just created in the list of R environments displayed. If this is your first time setting things up, there should only be the one entry you just created. Click on that choice, then hit “Default” to mark this as your default R environment. Hit Apply at the bottom of the Preference window.

You must click on your new environment on the list and click Default to mark it as the R environment to use when Eclipse launches R.

If you plan to use Eclipse to primarily work with R, you will probably want to set StatET as your default “Perspective” in Eclipse (rather than the Java perspective or a C++ perspective or many others). In the Preferences window, go to General>Perspectives in the list on the left. A list of the available Perspectives will be shown in the right panel of the Preferences window. Find StatET, click on it, and then hit “Make Default”. Hit Apply again, and then you can hit OK to exit the Preferences window.

Make StatET the default perspective in Eclipse.

Now that the R environment is established, you must create a “Run configuration” to launch a R console. In the main Eclipse window, go to Run>Run Configurations… This will bring up the Run Configurations window. Click on the R Console item in the list on the left and click the ‘New’ button (which looks like a sheet of paper with a + sign in the corner). Note: during my install, Eclipse froze here more than once. Eventually I was able to move through this step without freezing, but it’s not clear what the problem was.

Click on the R Console item in the list on the list, and hit New to create a new R Console item.

The new console setup section has several tabs. The first step should be to name your new console in the Name field at the top. Again, this is a point where giving a descriptive name to the console is important, particularly listing the R version it will open and the architecture it will use (32-bit or 64-bit), in case you want to run other versions of R in the future. Naming it “Mary’s R” will not be helpful if you later want to install a new version of R and keep the older version intact as well. I named my console R-2.12.0_x64_test to denote both the R version and the architecture.

Give the Run Configuration a descriptive name.

In the Main tab, leave “Launch Type” set to RJ. Below that, you can specify the initial working directory that you want R to open in. This will probably be whatever folder you keep the data that you’ll be manipulating in R. In this example, I’ve pointed it to D:\Eclipse\R_data.

Specify an initial working directory for R to start in.

Move to the R Config tab next. The R Environment listed here should be the Workbench Default that we created earlier.

Choose the appropriate R environment, which will probably be the default you created earlier.

In the R Console tab, I like to check the “Pin initial console automatically” box so that the R console opens in the Eclipse main window. Lower down on the tab, you’ll find options for Eclipse integration. I prefer to uncheck the “Enable R Help by StatET for R help functions” item, so that help pages open in my web browser instead of in a window inside Eclipse. Make sure that the Object DB boxes are both checked, which allows you to see the objects in the R workspace when you’re working.

There are several customization options on the R Console tab, including a choice for where to open help files.

The Common Tab has an option to have this R Console appear in the Run menu. Check the box next to Run to enable this.

The Common tab.

You can leave the Environment, JRE, Java Classpath, and Java Source tabs alone for now. I will note that if you’re trying to set up a 2nd R console under a different architecture (32 vs. 64-bit), you can use the JRE tab to specify the appropriate Java architecture to match your R session. If you’re trying to add a 32-bit R console session, you need to run it with a 32-bit Java runtime engine, just as you need to run 64-bit R with a 64-bit Java runtime engine.

At the bottom of the Run Configurations tab, click the Apply button to save these changes, and then hit Run to launch your R console. The first time you run R, Eclipse will pop up a window to ask if you want to index the R environment. I would check the Global option and hit Yes. The initial indexing of the R environment will take a few minutes if it’s a new install, but should be much quicker on subsequent launches.

It can also be handy to set up StatET to launch a R console every time you open Eclipse/StatET. To do this, go to the Window>Preferences menu item in the main Eclipse window. In the Preference window, go to Run/Debug>Auto Run. In the Auto Run panel on the right, check the box for “Enable run at startup of:”. Below that, click on the R Console item, and then click on the name of your R configuration. Hit Apply to save this option, and hit okay to leave the Preference window.

Setting up the R console to auto-run each time you start Eclipse+StatET.

Finally, if your R console is working, you can start a new “R-Project”. The R-Project will contain your various R scripts and Sweave files. You create a R-Project by going to File>New>R-Project. In the window that opens, give your R-project a descriptive name.

Create a new R project.

The default location to save the R-project files will be the workspace you created when you first started Eclipse. This may not be ideal for you, because it means that any R-script files you create in Eclipse will be stored in that folder. I prefer to have my script files reside in the same folder as my data files. As such, I uncheck the “Use default location” option and use the Browse button to point Eclipse to my R data folder. The upshot of this is that the directory structure displayed in Eclipse’s Project Explorer tab will reflect the directory structure of your R data folders. This is shown below.

The R-project directory file reflects my R data folder contents.

To write a new R-script, go to File>New>R-Script File. A window will pop up to let you name the file and specify where in your R-Project folder structure the file should be stored. A new editor tab will then open in the Main Eclipse window. Here you can type in your R code and take advantage of the colored syntax highlighting, code completion, and other features that make a real text editor so handy. You can also submit the script file to run in your R session with one click by hitting the “Run File” button just above the text editor tab. There are actually three Run buttons here, one to submit the whole file, one to submit a single line or selected lines, and one to step through each line of your file as you click the button.

Create a R script in the editor, and hit the Run File button to submit the file directly to your R console session at the bottom of the screen.

Among the other tweaks that I make to my configuration, I find it helpful to include a visual indicator of the 80-column width in the editor window. Keeping lines of code to less than 80 columns wide makes for nicer printing of hard copies of your files, since a standard sheet of US letter paper with 1 inch margins and 12-point font will just fit 80 columns of text without having to wrap to the next line. To insert a visual guide in the text editor window, go to Window>Preferences, and choose General>Editors>Text Editors. In the Text Editors panel you will find a check box for “Show print margin” above a field for “Print margin column.” Check this box to make a vertical line appear in the text editor window after the 80th column. You can also check the option to show line numbers here. Hit Apply and OK to exit the preferences window.

Setting up the visual indicator for 80-column width.

The 80-column line can be seen at the right edge of the text editor window.

A note about Java runtime engines.
There are 32-bit and 64-bit Java runtime engines (JRE) available for Windows, and a 64-bit version of Windows can have both installed. In some cases, if you want to run a 64-bit version of Eclipse (not R), you will need to download a 64-bit JRE. If you try to launch 64-bit Eclipse for the first time and it fails, complaining about not being able to find an appropriate JRE, you will probably need to download one. After installing the 64-bit JRE, it may still be necessary to add the 64-bit Java installation to the Windows search path so that Eclipse can find it. 64-bit Java will install in the C:\Program Files\Java folder (not the C:\Program Files (x86)\Java folder, which contains your 32-bit JRE). In my case the install lives in C:\Program Files\Java\jre6\bin. To put this folder in the Windows search path, hit your Windows key and type something like “set path”. You should see the “Edit the system environment variables” option come up in the results. Click on that option.

Edit environment variables.

In the window that opens, click on the Environment Variables… button.

The System Properties control panel. Click on the Environment Variables button.

In the window that opens, go to the System Variables in the lower section. Scroll down to the “Path” item, click on it, and hit Edit.

Edit the Path variable

In the Variable value field, insert you cursor and move to the very end of the list. Type a semicolon “;” to divide your new entry from the previous entry. Put in the path to the 64-bit Java install (C:\Program Files\Java\jre6\bin in this case.)

10 Responses to “R 2.12.0 and Eclipse with StatET installation”

  1. Alan.F said:

    Dec 15, 10 at 14:43

    Nice guide Luke. Helped me a lot. Couldn’t find a link to the rj file on the linked StatET homepage. Just in case anybody is looking the following url works:
    http://download.walware.de/rj/rj_0.5.0-5.tar.gz

    Alan

  2. Mike Rowe said:

    Dec 17, 10 at 23:00

    Hey,

    Thanks for the eclipse instructions; I’ve been looking for a good cross-platform R editor/IDE (I use both Windows and OS X) and will definitely check it out.

    I also miss the functionality of the Matlab IDE, especially the integration of the debugger with the editor. Fixing that was beyond my abilities, but I have written an R function, CodeBase(), that will automatically source all of your functions as long as they live within a single top level directory, and attach them in the first position of the search() path. You can call this at start-up so that every function you’ve written is available without having to source it. There are other functions that work along with CodeBase() that allow you to edit a function by typing “ed(my.fun)” and then re-source it by typing “s(my.fun)” (where “my.fun” is the actual name of the function.) You can enter comments between the function assignment and the function keyword, like:

    my.fun <-
    # my.fun is a function I use to demonstrate the usefulness of CodeBase
    # y <- my.fun(x=NA)
    # ARGUMENTS
    # x: a vector or something
    #
    # VALUE
    # y: a list containing the input argument x
    function(x=NA){
    … etc

    Then if you type "doc(my.fun)" at the command line it will print all this stuff the screen. I've also got a function to do a regular expression search of the documentation of all your functions and return those that contain particular keywords, to help you find a given function.

    Anyway, I've been using this for a couple of years, as have my coworkers at the start-up I work for. It makes me miss the Matlab IDE a little less. I haven't gotten around to putting it into a package and submitting it to CRAN, 'cause that seems kind of involved, but I would if enough people seemed interested.

    What do you think?

    Cheers,
    Mike

  3. Shankar Anand said:

    Dec 21, 10 at 17:50

    Great guide. Thanks a lot.

    I had one question. I followed the steps, however, I did not see the Object DB options as you had mentioned – “Make sure that the Object DB boxes are both checked, which allows you to see the objects in the R workspace when you’re working.”
    Any ideas?

    I was setting up R-2.12.1 (x64 on Eclipse Helios).

    Thanks

  4. Luke Miller said:

    Dec 21, 10 at 20:08

    When you’re in the Run Configurations window, on the R Console tab, make sure you scroll down past the “R snippet run at startup” box to reveal the “Eclipse Integration” portion of the window. You should find the ObjectDB options there. In Eclipse Helios, that section may be initially hidden at the bottom of the tab, which is different from the images here that show the Eclipse Galileo installation.

  5. Omari said:

    Dec 28, 10 at 18:15

    Thanks for the guide. I have a quick question. Is there a reason why when I run:

    R CMD INSTALL –no-test-load rj_0.5.0-5.tar.gz

    I get the error:

    “This application has failed to start because jvm.dll was not found. Re-installing the application may fix the problem.”

    I have the jvm.dll file and I have re-intalled the application yet still i get the same error.

    Thanks in advance

  6. lukemilladmin said:

    Dec 28, 10 at 20:11

    I’m not sure what would cause that error. I’d make sure that RJava installed correctly in R before trying to install rj. If that doesn’t improve things, try posting an inquiry to the StatEt users email list at .

  7. lukemilladmin said:

    Jan 07, 11 at 11:33

    http://lists.r-forge.r-project.org/mailman/listinfo/statet-user

  8. Revolution R with Eclipse Helios | Nathan VanHoudnos said:

    Jan 10, 11 at 12:08

    […] the break, I ran across Luke Miller’s excellent post on getting Eclipse setup with StatEt the right way. I was able to follow his tutorial to get vanilla 64-bit R setup on a new installation of 64-bit […]

  9. Brian Bolt said:

    Jan 13, 11 at 14:31

    Thank for the tutorial. It worked great for my first R configuration (64 bit) but I ran into problems when I tried to add a second, 32 bit, configuration. I wanted to add this second configuration because one of my scripts relies upon a package that is 32 bit dependent.

    The problem I am having is that when I try and add an R environment for 32 bit, and I click the “Detect Default Properties/Settings”, my architecture reverts to 64 bit. If I change the architecture back to 32 bit and i366 and then save. My configuration still launches the 64 bit version in the console. Have you seen this behavior before?

  10. lukemilladmin said:

    Jan 13, 11 at 17:11

    After you create the new 32-bit R environment, you still need to create a new Eclipse Run Configuration for that particular (32-bit) environment. The setup steps are similar to those you used to originally create the 64-bit run configuration. Go to Run> Run Configurations. In the window that opens, choose “R Console” in the tree on the left, and click the “New” button near the top of the window to create a new configuration.

    Near the top of the main section of the Run Configuration window, give the new configuration a descriptive name besides “New_configuration”. Next, under the “R Config” tab, you will need to change the selection from “Workbench Default” (your existing 64-bit version) to “Selected Configuration” and choose the 32-bit R environment you created. This will probably create a warning at the top of the window that says “Selected R and Java environments are not compatible, R = 32-bits, JRE = 64-bits”.

    If you get this error, you need to move to the “JRE” tab and designate an alternate (32-bit) Java Runtime Environment. Click on the “Installed JREs…” button on the far right to open a window where you can add a 32-bit JRE (recall that 32-bit JRE’s will normally be installed in C:\Program Files (x86)\Java). Be sure to give the new JRE a descriptive name (JRE_32bit). Close that window, return to the Run Configurations JRE tab, and choose your new 32-bit JRE from the drop-down menu of Alternate JRE. The warning at the top of the window should disappear now that you’re running 32-bit R with a 32-bit JRE. You can make your other preferred customizations to the run configuration, hit Apply to save the new configuration, hit Run, and see if the new 32-bit version launches.

    The preamble of the R session that starts up should include the line “Platform: i386-pc-mingw32/i386 (32-bit)” to prove that you’ve got a 32-bit version running.

    The 64-bit R version will probably still be the default that launches if it is set as the default R environment, but you can launch your 32-bit R by going to Run>Run History and choosing your 32-bit configuration on the occasions you need to use that version.