I’m interested in running R on the Raspberry Pi, and on Raspbian in particular. There are loads of Debian packages for R, and I’m hoping that many of these find there way into Raspbian eventually. Right now it is possible to install and run R from Raspbian, but relatively few packages are available. However, the package `r-base` can be installed, and that is enough to get up and running with a basic R installation. So,

% sudo apt-get install r-base % R

should be enough to get started. Indeed, here’s a little Raspbian session to illustrate R running on the Pi:

pi@raspberrypi ~/src/r $ uname -a Linux raspberrypi 3.1.9+ #168 PREEMPT Sat Jul 14 18:56:31 BST 2012 armv6l GNU/Linux pi@raspberrypi ~/src/r $ R R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0Platform: arm-unknown-linux-gnueabihf (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > rnorm(5) [1] -1.8385888 -1.1114294 0.7943391 1.0070076 0.7702747>

Nice! Base graphics such as scatter plots and histograms all work fine, and can be piped to a remote X server if needed. So even without all the add-on packages it is a perfectly reasonable platform for basic data analysis. To benchmark it, I used my standard Gibbs sampling script, `gibbs.R`

gibbs=function(N,thin) { x=0 y=0 cat(paste("Iter","x","y","n")) for (i in 1:N) { for (j in 1:thin) { x=rgamma(1,3,y*y+4) y=rnorm(1,1/(x+1),1/sqrt(2*x+2)) } cat(paste(i,x,y,"n")) } } gibbs(50000,1000)

which I can run and time from the linux command line with

% time Rscript gibbs.R > /dev/null

Unfortunately, this takes over 400 minutes, which is around 3 times slower than the equivalent python benchmarking script that I have run on Raspbian. On Intel, R is around half the speed of python, so there’s a bit of a gap there, but actually python runs slower than it should on the Pi anyway. Comparing against R on Intel, on my fast i7 laptop, this R script takes around 7 minutes, and on my Atom based netbook, it takes around 57 minutes. This is consistent with my other findings – namely that the speed difference between C and higher level languages is greater on the Pi than on Intel. Nevertheless, for many basic data analysis tasks, speed isn’t that much of an issue, and it’s certainly going to be very convenient to have R on the Pi.

AnonymousUPDATE: Updated post to reflect the fact that r-base now installs fine.

Pingback: Raspberry Pi How to Install R on the Raspberry Pi | Matthew Moisen's Blog

robinattynemouthrobingreat there seems to be many R packages now – I’m in the process of writting a introductory stats book using mainly R commander and that even works on the raspberry pi – also note that ggplots is available – be great for teach kids etc.

Ilyass T.So when I install r-base, I only get R version 2.14 or something, which is not version 3, the current version of R,

is it possible to get R version 3 on the Raspberry?

Also, I’d really like to use ggplot2 on my Raspberry, but when I try installing it, I get a mistake because of Rcpp which cannot be installed on R,

could anyone help me?

Thanks