[This article was first published on DataScience+, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Many R users enjoy working in RStudio, but it’s not your only option for reproducible research in R. Stephen Wahlbrink has written a plugin for Eclipse, Statet, that offers similar functionality to RStudio within the popular Eclipse framework. You can run an R console, compose a document in LaTeX with R code chunks, and link the two through Sweave and the plugin.

## Why choose Eclipse and Statet for R?

This stack isn’t for everyone, but here are some reasons to prefer Eclipse and Statet over RStudio.

• You dislike software that randomly crashes and loses your work
• You are already familiar with Eclipse and use it for other programming tasks.
• You use two monitors. With Eclipse, you can detach and position your work windows wherever you like and make full use of all your screen space. In RStudio, the console and editor windows always remain within the application frame, limiting you to one monitor.
• You like writing in LaTeX or need print quality output. RStudio is probably the better choice if you prefer to write in rmarkdown, but its support for LaTeX is weak. At the time of writing, RStudio will not produce a pdf from LaTeX that contains R generated graphs. Presumably, this is a bug and not a feature and it will be fixed at some point. However, the developers seem to favour markdown and HTML. Currently, support for LaTeX and pdf’s is not as good.

## Installation guide

The Eclipse stack is not as easy to get up and running as RStudio, but it is considerably more stable once you have it working. No worries: this tutorial will walk you through every step of the way. The instructions shown here are based on a clean install of Kubuntu 16.04 and current versions of everything else, as of May 2016. These instructions should work for any Debian based distro. Most of this will also work with Fedora/Centos/RHEL, but I have sometimes found it harder to get up to date versions of things from the repositories these distros use.

Eclipse is cross-platform and this stack is also available to Windows users. The installations are similar, and I specify the differences in the details section. I have used Eclipse/R/Statet on a Windows system without administrator privileges and behind a firewall. I suggest tips for other users in similar controlled environments.

Here is an overview of the what you need to do.

• Install Java.
• Get Eclipse.
• Install R
• Obtain a LaTeX distribution
• From within R, install packages rj and rj.gd from Walhbrink’s site.
• From within Eclipse, install the Statet plugin.
• Launch Eclipse and configure for use with R and LaTeX

Warning: Don’t mix the bitage. Go 64 bit on everything, or 32 bit.

Most of the time, if I have an issue with installing Statet and Eclipse, it’s because I mixed 32 and 64 bit applications. The rest of the time, problems came from badly installing Java.

### Install Java

On windows, you only need the runtime version (JRE) and you probably have this already. On Linux, you need the JDK, because R needs the JDK to compile the rj and rj.gd packages.

Get Eclipse : Download the current version from Eclipse.org.

Linux users : Avoid sudo apt-get install eclipse and download directly from the site. The repos are often out of date.

### Install R

You probably know how to do this already. A note to Windows users in controlled environments. Most of this can be done by users without administrative privileges. However, you will save yourself some trouble later on if you can convince your IT department to do the install for you. They can ensure that the location of your R install is preserved in the Registry. This makes it a lot easier for Eclipse to find R when you want to summon the console.

### Install a LaTeX distribution

Windows users can install MikTex 2.9 from the installer. If you work behind a firewall, be sure to get the complete installation. The default provides a basic selection of packages and installs the rest as needed, on the fly. Your firewall won’t like that.

Warning! The Recommended Download is the 32 bit version. If you are going 64 bit, be sure to download the 64 bit version under Other Downloads.

Linux users can use the version from the repo. If you use the synaptic package manager, go for texlive and texlive-extras, plus any other packages you expect to need. Texlive won’t install packages on the fly, so you need to get all the packages you use up front.

### Extra instructions for Windows users

Windows users also need to inform Miktex where to find the Sweave.sty file. To do this:

• Open Miktex Settings. This program comes with the Miktex installation. There is another program called Miktex Settings (Admin). Ignore this one and use the plain Miktex Settings.
• Select tab Roots.
• Click Add and navigate to folder ..\my R installation\share\texmf
• Select this folder, save and exit Miktex Settings. You’re done.

You may have noticed that Sweave.sty is not actually in the texmf folder. It’s a couple of folders lower down, but this is the folder that Miktex needs to know about.

### Install R packages rj and rj.gd

rj and rj.gd are R packages used to form a bridge between R and Java. You need these to run the R console from Eclipse. These packages are not hosted on Cran, and you need to download them from www.walware.de.

• Launch R
• Navigate to Wahlbrink’s download page for rj and rj.gd.
• Copy the appropriate install code for the version you need and paste into your R console. Typically, you want the first line in the list. The other options refer to earlier versions of Statet, used with earlier versions of Eclipse. At the time of writing, you would enter the following code at the R prompt.
• install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-2.0")
• Quit R

Under Linux, the previous step may take a few moments while the packages compile. You may get an error message to the effect that the system could not compile a simple JNI program. This means that you failed to correctly install the Java JDK, or that R cannot find it. Googling the error message leads to a helpful post on Stack-Overflow, which should resolve the issue. Basically, you need to run sudo R CMD javareconf before attempting to install rj and rj.gd.

If you work behind a firewall, you can do a manual install by downloading the packages from Walware through your browser, .

### Installing the Statet plugin

From Eclipse, install the Statet plugin. As with rj, the plugin can be downloaded and installed manually, or installed on the fly from Eclipse. You want the version that works with the version of Eclipse that you previously installed. In most cases, you will be using the current version of Eclipse with the most recent version of Statet, but if you have reason to maintain a legacy system, earlier versions of Statet are still available on Walware.

In the following screenshots, I install the current version for use with Mars Eclipse. You can click on the images to enlarge them.

Check Walware for the current version of statet and copy the download url. The cursor on the my screenshot (low and center) points towards the line I need to copy.

Now launch Eclipse. Select Help -> Install New Software.

Click Add (top right). A form opens where you paste the URL from Walware. You can also give the plugin a name. On the screenshot, I’m about to click OK.

Eclipse goes onto the Internet and retrieves some information from Walware. It finds 5 plugins. Check the box beside Statet. Do not select the other boxes.

Click Next. The plugin will now download and install. Various screens will appear asking you to agree to the license and warning about unsigned content. Agree to everything and accept everything. Congratulations! You have Statet.

While we’re installing things, let’s grab Ahti Kitsik’s word wrap plugin. As before, select Help -> Install New Software. Click Add and insert Ahti’s download url for the plugin, http://www.ahtik.com/eclipse-update/. Give it a useful name, click OK and proceed as before.

Now exit Eclipse to complete the installation.

### Configuring Eclipse

We have all the tools, but we’re not done yet. We still need to configure Eclipse so that it knows:

• Where to find the R version you are using
• How you want to run R (from which folder, with which Java, etc.)
• Where to find LaTeX and how to run it.

If you have never used Eclipse before, it is easy to get lost at this point. I have supplied detailed instructions with screen shots in part 2 of this tutorial.

Related Post