R on the Raspberry Pi

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

        for (i in 1:N) {
                for (j in 1:thin) {

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.

Published by


I am Professor of Statistics within the Department of Mathematical Sciences at Durham University, UK. I am an Bayesian statistician interested in computation and applications, especially to engineering and the life sciences.

10 thoughts on “R on the Raspberry Pi”

  1. great 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.

  2. 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?


    1. Interesting. I must have something wrong with my setup. I ended up getting 95 min on my Pi 3 w/ Jessie and R v3.1.1.

      1. I’ve run some more simulations getting between 47.5 & 49.5 mins user time… 47.5 with no other processes (beyond an x-session) and 49.5 when running iceweasel at the same time. Maybe you had some memory paging going on?

  3. On an “Orange Pi PC 2” (excellent and very cheap Pi3 workalike [faster/better specs and cheaper] from china; see http://www.orangepi.org/orangepipc2/) the Rscript takes 42 minutes.

    This is running under R version 3.2.3 under Armbian 5.34.x (ubuntu server 16.04.3 LTS 4.13.14-sunxi64).

    I have three of these OPi PC2s and a OPi Plus 2E all networked on a gigabit switch (yes these Orange Pi’s have real gigabit ethernet 😎 .. looking into some cluster experimenting.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s