## Quantum Forest

### notes in a shoebox

I wanted to develop a small experiment with a front end using the Processing language and the backend calculations in R; the reason why will be another post. This post explained the steps assuming that one already has R and Processing installed:

1. Install the Rserve package. This has to be done from source (e.g. using R CMD INSTALL packagename).
2. Download Rserve jar files and include them in the Processing sketch.

For example, this generates 100 normal distributed random numbers in R and then sorts them (code copy and pasted from second link):

The problem is that this didn’t work, because my OS X (I use macs) R installation didn’t have shared libraries. My not-so-quick solution was to compile R from source, which involved:

1. Downloading R source. I went for the latest stable version, but I could have gone for the development one.
2. Setting up the latest version of C and Fortran compilers. I did have an outdated version of Xcode in my macbook air, but decided to delete it because i- uses many GB of room in a small drive and ii- it’s a monster download. Instead I went for Apple’s Command Line Tools, which is a small fraction of size and do the job.
3. In the case of gfortran, there are many sites pointing to this page that hosts a fairly outdated version, which was giving me all sorts of problems (e.g. “checking for Fortran 77 name-mangling scheme”) because the versions between the C and Fortran compilers were out of whack. Instead, I downloaded the latest version from the GNU site.
4. Changing the config.site file in a few places, ensuring that I had:

Then compiled using (didn’t want X11 and enabling shared library):

And finally installed using:

This used a prefix because I didn’t want to replace my fully functioning R installation, but just having another one with shared libraries. If one types R in terminal then it is still calling the old version; the new one is called via /luis/compiled/R.framework/Versions/Current/Resources/bin/R. I then installed Rserve in the new version and was able to call R from processing so I could obtain.

A ‘hello world’ of the calling R from Processing world.

Now I can move to what I really wanted to do. File under stuff-that-I-may-need-to-remember-one-day.

1. Hi Luis,
Great Post! I played around with R and Processing while back on a Mac as well, but was lucky not to run into the problems with shared libraries: http://lamages.blogspot.co.uk/2012/10/connecting-real-world-to-r-with-arduino.html. I haven’t used Processing with R since, so I look forward to your next post for ideas and motivation to get my Arduino out of the drawer again.
Thanks
Markus

• Luis

2013/12/20 at 8:13 pm

You’re most welcome. I’m glad the post was useful for someone else.

2. yes, I’m in the process of learning Processing so I can use it with Data. In the back of my mind, I’ve been wondering how the two can connect. Much thanks.

3. Hi Luis,
I manage my installation of R on my mac using homebrew. Because homebrew builds R from source anyway, it was easy to just add the –enable-R-shlib option to the standard build script by using the “brew edit r” command. Thanks for the interesting post!