Tuesday, September 22, 2015

Compile and Install R-3.1.2 (32-bit) in Raspberry Pi Model B/B+

Hey guys,

It's been a while since my last post. I've been playing with RPi for some chart plotting features recently and i found out that Raspberry Pi can in fact install pretty recent version of R. In this case, R-3.1.2. I've been using R for my work since few years ago and still loving it. Therefore i tried to install it into my RPi to see how it perform. The available version of R in apt-get repo is quite old, so in order to get more recent version of R, I have to compile it in RPi instead and install it in the system. I'll describe how to do it step by step in the next section.

** Note: Since we are compiling R, i do not recommend to run the compiling over SSH. Instead please start a desktop session through tightvnc. If you don't want to install tightvnc, you can connect your RPi to a monitor, keyboard and mouse during compiling.

When your desktop session is ready, please double click LXTerminal icon on the desktop and you will see a terminal window show up.

  1. We are going to need some extra packages installed in RPi in order to compile R. In the terminal window, type in "sudo apt-get install gfortran libreadline6-dev libx11-dev libxt-dev libpng-dev libjpeg-dev libcairo2-dev xvfb" (without the quote) and follow instruction from the apt-get prompt to install the necessary packages.
  2. Once complete step 1, type in "mkdir R_HOME && cd R_HOME", this command will create a folder name "R_HOME" under "/home/pi/" and then enter the new directory "R_HOME"
  3. Next, type in "wget http://cran.rstudio.com/src/base/R-3/R-3.1.2.tar.gz && tar zxvf R-3.1.2.tar.gz"  to download R-3.1.2 source archive file into the folder and extract it into "R_HOME" folder.
  4. Next type in "ls" command to ensure you have one directory "R-3.1.2" and the archive file "R-3.1.2.tar.gz" in "R_HOME" folder.
  5. Next type type in "cd R-3.1.2" to enter the extracted directory.
  6. Finally type in "./configure --with-cairo --with-jpeglib && make && sudo make install" to start source code compilation and installation. Take note that this process will take several hours to complete due to RPi's slow processor speed. You will see a lot of messages pop up in the window, just leave it until the process complete. After that you will see "pi@yourhostname ~/R_HOME/R-3.1.2 $" popup in window where yourhostname is the hostname you set for your RPi. Once you see that line that means the compilation and installation is complete.
  7. To verify whether R installation is complete, simply type "R" and type enter in the terminal window. You will see R console start up like figure below if everything goes well.

Well, that's it for now. I'll share some example of installing R packages like ggplot2 and running R to plot charts in the next post when I'm available.

Thanks for reading =)

Edit 20th Nov 2014: 
1. Add in additional libraries required at step 1 to enable additional plot output format capabilities (jpeg and png) on R during configuration.
2. Add in ./configure parameters at step 6 to ensure R compile with jpeg and png capabilities.

1. http://stackoverflow.com/questions/28309891/install-r-3-1-2-on-wheezy-7-8-raspbian-fails
2. http://r.789695.n4.nabble.com/Compiling-R-3-1-0-on-debian-with-libpng-libjpeg-td4693026.html

No comments:

Post a Comment