How to Install the Latest Version of R Statistics on Your Raspberry Pi

R for Beginners:  How to Install the Latest Version of R Statistics on Your Raspberry Pi

A tutorial by D. M. Wiig

One of the nice characteristics of open source software such as R is the rapid development of new releases and updates.  While the base core remains stable for a period of time there is a considerable amount of updating,  adding, and removing the component packages.  At the time of this writing the latest iteration is R version 3.3.1, “Bug in Your Hair.” If you are using a Windows platform you will likely go directly to the archive web site and download the latest distribution as a Windows executable installation package.

If you are using a Linux distribution  such as Ubuntu or Debian, the process of adding software is usually accomplished via the menu based installer.  These software installers allow  R and its dependencies to be downloaded from the community archive.

One of the disadvantages of using this approach is that the versions of some software in the community archives may not be updated to the latest version.  This is often the case with R as well as with many other software packages.

To insure that you are downloading the latest R version you need to use the platform’s command line to install what is needed.  You can add the URL’s of some backport archives that are more likely to be kept up to date with current releases.  As an example In this tutorial I will use the R statistical software that I am running on my Raspberry Pi 3 board with a Raspbian OS and the new PIXEL desktop.

Regardless of which Linux distribution you are using first open a command console from the desktop menu. Make sure all is up to date by using the command:

pi@raspberrypi:~ $ sudo apt-get update
This will insure all appropriate packages currently installed are running the latest updates.  If you are running a Raspbian distribution such as jessie you will need to edit the /etc/apt/sources.list file to add a backport to the latest version of R.  Start the nano editor by using the command:

sudo nano /etc/apt/sources.list

This should produce the output as seen below:

pi@raspberrypi:~ $ sudo nano /etc/apt/sources.list

GNU nano 2.2.6 File: /etc/apt/sources.list

deb jessie main contrib non-free r$
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
deb-src jessie main contrib non-free rpi
deb stretch main
deb jessie main
deb xenial/

[ Read 8 lines ]
^G Get Help ^O WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos
^X Exit ^J Justify ^W Where Is ^V Next Page ^U UnCut Text^T To Spell

As is seen above there are several lines containing the standard  Raspbian archives to search.

If you are using a Debian distribution you would add the following line to the file: jessie main

Replace the 'jessie' portion with the name of the specific Debian distribution you are using replace the 'mirror' portion with the R CRAN mirror that you use.  You also need to add the line that provides the URL of a Raspian 'stretch' archive that contains the most recent updates of many different software packages.  In my case I was looking for the latest R release, but you should search this this archive for the latest version of any software package you are installing.

If you are using an Ubuntu distribution add a line with the appropriate changes for the specific Ubuntu distribution that you are using. 
Check with the documentation provided with your specific Linux distribution to see if there is also a 'stretch' archive maintained for new versions. 

Once these changes are made exit the nano editor using the ^O key command to write the file and then the ^X key command to return to the command line.  You should now be able to issue the command:

pi@raspberrypi:~ $ sudo apt-get install r-base r-base-core r-base-dev

Once the download and install processes have completed you should now be able to invoke R from the command line or menu and see the latest version:

pi@raspberrypi:~ $ R

R version 3.3.2 RC (2016-10-23 r71578) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: 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.


For other Linux distributions you would add a line similar to the above examples in the /etc/apt/sources.list. Check the documentation for your specific Linux platform for further information about backport archives.


6 thoughts on “How to Install the Latest Version of R Statistics on Your Raspberry Pi”

  1. Hello, can you tell me if other packages usually work well with the ARM version of R in Raspiberry Pi 3? I am planning on buying one but I am not sure if only the ‘base’ R will be working or if I will be able to install and use other packages as well.


    1. So far I have used R installed on a Raspberry Pi B a Pi 2 and a Pi 3. The only thing I have not been able to run is R Studio and R Shiny. These packages will not run on an ARM processor. There are probably others as well but the R Base, R-Base-Core and R-Base-Dev all work fine on a Pi. The various Java and other dependencies that some R packages require will also install and work well. I have used both Raspbian Jessie (Debian) and Ubuntu OS distributions with the Pi.



      1. Thanks for this post. I was interested in this because Pixel OS is now released and will soon be available as standalone OS. If shiny is not supported, then the attractiveness drops down. RStudio is a great IDE but I can live without it. However, since it may still be possible to do D3 based rendering if for example htmlwidgets package works (which it should)…So I will give it a try.


  2. I followed your tutorial (first time with a Pi and years without using Linux) and I got R running very easily! Thanks! Do we only have access to this “LXTerminal”? I code on a Windows and run the code on the Pi, so it’s just a curiosity, this terminal does everything I need.


    1. You can load a Java based GUI to run R programs in on your Linux platform. It makes it a little easier to work with packages and allows you to edit code in a basic code editor. I have a tutorial of the subject posted on the blog. The GUI is called JGR.



  3. Hello,
    Thanks for the tutorial on installing R on the Pi, but I get an error when I try it. I use Raspberry Pi 3, Model B.
    I edited the /etc/apt/sources.list as you describe, but when I run:
    sudo apt-get install r-base r-base-core r-base-dev
    I get this error:
    The following packages have unmet dependencies:
    r-base : Depends: r-base-core (>= 3.3.2-1xenial0) but 3.3.2-1 is to be installed
    Depends: r-recommended (= 3.3.2-1xenial0) but it is not going to be installed
    Recommends: r-base-html but it is not going to be installed
    r-base-dev : Depends: r-base-core (>= 3.3.2-1xenial0) but 3.3.2-1 is to be installed
    E: Unable to correct problems, you have held broken packages.

    I did run sudo apt-get update before all the above…

    Any help is appreciated!



Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s