Tilastotieteellistä ohjelmointia R-kielellä

R on Android

I have been trying to get R to work on an Android-based device without a need to root the device. I finally found a way to do it!

The solution is based on a Linux installation, GNURoot, that does not require rooting, and the Debian distribution, Gnuroot wheezy, that is meant to be used with GNURoot. Both are available from Google Play, formely Android Market. The installation process goes as follows:

1. Install GNURoot from Google Play
2. Install Gnuroot Wheezy from Google Play. See http://www.linux-magazine.com/
   for more help.
3. Update the package repositories (twice!):

   apt-get update
   apt-get update

4. Block updates to system Perl:

   apt-mark hold perl-base

5. Install R:

   apt-get install r-base

6. Install all available cran packages from the Debian repositories:

   apt-get install r-cran*

7. Start R from the command line:


Unfortunately installing Debian package build-essential runs into problems (a form of a dependency hell, that is), and installing new R packages that would require compiling C or Fortran code is not currently possible. Otherwise the installation seems to work rather nicely.

Another major restriction at this point is that it is not easy to install a graphical user interface to the Gnuroot Wheezy, and therefore you can’t, e.g., see the generated images straight up.

Furthermore, the technique described above installs R version 2.15.1. It supports more binary Debian packages of the R packages than the more current R version. However, if you need a newer R version, you could follow the instructions at CRAN to setup the correct R Debian repository for a newer R version.

This solution has been tested on mobile phone Samsung Galaxy S4 Plus (GT-I9506) running Android version 4.2.2.

EDIT (2014-02-10): See the comment by Corbin Champion below. R 2.5.1 can now be installed in GNUroot Wheezy with the following three commands:

apt-get update
apt-get install r-base
apt-get install r-cran*

It works like a charm now!

EDIT (2014-02-10): Hint regarding working directories on Android: The external SD Card can be used for analyses, if you first set up the working directory as setwd("/mnt/extSdCard/"). Similarly, the built-in memory area is located at setwd(”/sdcard/”). Setting the working directory on either sdcard to a suitable directory allows you to generate plots directly to files using functions such as png(), pdf() and jpeg(). These require the suitable drivers, and you can check your current R builds capabilities with the function capabilities(). Plotting does not work, if the applicable file formats are listed as FALSE under printed capabilities list.

Note that this information is provided with best of intentions, but for all purposes, you use it at your own risk.

37 Responses to “R on Android”

  • Corbin kirjoitti:

    Just pushed a new version of gnuroot and the various roots. If you updated to the latest of say GNURoot Wheezy and GNURoot, you should be able to do simply:
    apt-get update
    apt-get install r-base
    No longer need to work about the problems with perl or other dependencies.
    The version is brand new, so no testing by others, but this works for me now.

  • Dr No kirjoitti:

    Excellent, brilliant or fantastic?

    All of them!

    One detail I miss is the memory of previous commands normally available via the arrow buttons.

  • Jarno Tuimala kirjoitti:

    @Dr No: You can install Hacker’s Keyboard from the Google Play, and use it as an input device. The Hacker’s Keyboard has arrow keys, and allows you to browse through the command history in R.

  • Arucard kirjoitti:

    Hint! If you install Pelya’s XSDL Server from Google Play, you can use X11 aplications, then you can use graphical extensions of R language.
    So in Debian Shell (Terminal Emulator) tipe:
    # apt-get install xfce4
    It will install the XFCE4 Desktop Environment and Xorg with some utilities.

    And after several minutes of packages downloading and making configurations, start XSDL and set your favorite display resolution and zoom, and then type on the shell:
    # DISPLAY= startxfce4

    Switching to XSDL app, the XFCE4 starts and you can now use the Terminal application to install another software packages for R ou even graphical applications.
    So far, the Qt based programs (Calligra, Qt Creator, …) runs better than GTK applications on GNURoot.

  • Oliver kirjoitti:

    Very useful, thank you very much! I can use R on Android now, but it seems that the data sets didn’t work. Have you met with this problem?

  • Jarno Tuimala kirjoitti:

    @Oliver This seems to be a known bug (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=695411). It has not been successfully fixed yet in R 3.0.2, though. However, for some packages a command like `data(animals, package=”cluster”)`does seem to work. As a general workaround, you can source in the datasets stored in, e.g., dataset package: `source(”/usr/lib/R/library/datasets/data/cars.R”)`.

  • Oliver kirjoitti:

    @Jarno Tuimala Thank you! The command ’source(“/usr/lib/R/library/datasets/data/cars.R”)’ is very useful!!

  • kinray kirjoitti:

    Thanks! I have R working on my Nexus 4 now! However, in trying to get graphics working, I followed Arucard’s advice and installed xfce4, and ran the command ”DISPLAY= startxfce4” (without quotes), only to get the error: X server already runing on display Any ideas on how to fix this error?

  • Arucard kirjoitti:

    If you get x server already running, this means you should minimize the gnuroot application from your Android task manager and switch to your Android’s x11 server.
    (search for xsdl on Google Play) and install the Pelya’s one (xsdl server).
    This application will ask to set a default font size and the screeen resolution, then it will wait to any remote X server. (the blue screen with instructions is just an example)
    Open the XSDL server before running gnuroot, and then start the pipe:

    # DISPLAY= startxfce4

    switch to XSDL or wait about 30 seconds before to do so(the last version of XSDL cause a severe delay to start the DE). Once the black screen is gone, you should get the Debian’s xfce4 Desktop (may ask to start the panel, so do execute it). Now you have a full Linux environment (with some limitations), and with some work, you can install (almost) the same Linux software on your tablet.
    (I managed to install the jDownloader, for example, but require a hack to fix the JRE.)
    For now I sugest to install Midori and Iceweasel (Firefox fork), since the last one was updated to a most recent version (24) and support the Lightspark plug-in (an open-source Flash Player, but not so compatible to Adobe flash).

  • Tim kirjoitti:

    I have the following error message. Do you have any idea of how to solve this problem? Thanks!

    The following packages will be upgraded:
    libc-bin libc6 libssl1.0.0 3 upgraded, 189 newly installed, 0 to remove and 7 not upgraded.
    Need to get 0 B/113 MB of archives. After this operation, 278 MB of additional disk space will be used. Do you want to continue [Y/n]? y
    Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/Debconf/Config.pm line 22. Extracting templates from packages: 100% Preconfiguring packages …
    Can not write log, openpty() failed (/dev/pts not mounted?) dpkg: error: requested operation requires superuser privilege E: Sub-process /usr/bin/dpkg returned an error code (2)

  • Jarno Tuimala kirjoitti:

    @Tim Just a couple of thoughts. Have you upgraded GNURoot to its latest version, and if so, have you also ticked the box for ”Launch as fake root” when starting the GNURoot?

    By the way, there is also a new way to use on Android. The Google Play show now has a new app ”R Console” that allows usage of base R. It is not a fully functional R, at least at this time, since it does not allow installing new packages, and it does not display graphics at all.

  • J kirjoitti:

    I got the same error message as Tim. Also, once all this is installed how to you actually launch R on your Android?

  • J kirjoitti:

    When I type R at the command line I get: command not found.

  • J kirjoitti:

    Good lord. This is a mess. It doesn’t work and my phone is now tanking. I can’t even uninstall this crap. Thanks!

  • J kirjoitti:

    %$#$#[email protected]$$!

  • Jarno Tuimala kirjoitti:

    @J I’m sorry it doesn’t work on your phone. Unfortunately I only have Samsung Galaxy S4, and I can’t test the installation on any other system. For me uninstalling the GNURoot and GNURoot Wheezy removes the programs, and all R related installations in it from the system.

  • charizio kirjoitti:

    same problem as J, can’t get it run into my S3. ticked fake root

  • Kartikey kirjoitti:

    Thank You! It was very helpful! :)

  • Liam kirjoitti:

    Thanks for this – worked perfectly on my Sony Experia Z

    However since a recent system update gnuroot doesn’t work anymore. It gives the following message

    /system/bin/sh: /system/etc/mkshrc[9]: getprop: not found
    /system/bin/sh: /system/etc/mkshrc[10]: id: not found

    And then no commands work eg even cp or ls don’t work. Even after uninstalling and reinstalling gnuroot it’s the same. Anyone encountered and resolved this?

    Has anyone else found this?

  • Jarno Tuimala kirjoitti:

    @Liam: have you removed and reinstalled both the gnuroot and the wheezy or the other OS that you use with it, and did it make a ny difference? But note that there seems to be a bug with uninstall/install with at least certain Android devices, so I’m not sure this is always really advicable, unless you’re ready to do a factory reset (see https://code.google.com/p/android/issues/detail?id=65790).

    However, I have not encountered either problem with my Samsung mobile devices, even after system updates. Maybe this is a problem you might consider reporting to the original developer of GNUroot? It is somewhat hard for me to debug these issues, since I’m not a developer of gnuroot, just a user.

  • rabil kirjoitti:

    Re Dr. No’s comment that there is no up arrow in gnuroot. This is not so. If you open the menu for gnuroot there is an item for special characters. To get an up arrow you press the volume up and w.

  • Carl Witthoft kirjoitti:

    Hi, thanks for the excellent tutorial. I’ve got a question: how do I change the font size in xterm? I tried setting up a file ”.Xresources” with the line

    xterm*font: *-fixed-*-*-*-18-*
    as suggested in various forums, but no matter what fontsize I put in, I get the same teeny font.
    Any ideas? Or do I need to reduce the resolution of the entire x-server window to magnify things?


  • Carl Witthoft kirjoitti:

    Followup: I found the error message back in the Debian terminal session that xterm couldn’t load the font. How do I download and install fonts so that , e.g. ’*-fixed-*-*-*-36-*’ will load the appropriate size font?

    thanks again

  • Jarno Tuimala kirjoitti:

    @ Carl Witthoft: Does your Debian installation have the xfonts-base package installed? If I recall right (can’t verify it right now), that was the Debian package containing the fixed font. You might need to uninstall the xterm, install the font package, and then reinstall xterm.

  • Carl Witthoft kirjoitti:

    Thanks, Jamo, I’ll try that and post back w/ results.

  • Carl Witthoft kirjoitti:

    I loaded both xfonts-base and xfonts-terminus, reloaded everything in the xfce4 app, and same problem. I also notice that I can’t seem to access the menubar items that are discussed at http://docs.xfce.org/apps/terminal/preferences , but I don’t know if that’s because this Android vsn is stripped down.

  • […] my preferred solution came with GNURoot (see this tutorial), and here’s how I managed to install the newest CRAN […]

  • Brian kirjoitti:

    I have succeeded in installing rgl library in R, but when load it in xsdl it says that server doesn’t have glx extension and error in rgl_init. I have installed debian library for glx and add xorg.conf to /etc/X11 but no success. What can I do or is it not doable? Thanks.

  • Luis kirjoitti:

    No longer available from play market. Reasons ignored…

  • webera kirjoitti:

    Installed successfully on Fly IQ4406. However, for some reason cannot source() any of the built-in data sets as @Jarno Tuimala wrote, it throws ”file not found” although I put the path correctly.

  • Sreenesh kirjoitti:

    I have Motorola device . All instructions followed and R installed successfully.however when launching R , I get error message ”R command not found”. Any help?

  • Jon kirjoitti:

    Hi! I followed everything you said. But i got this error:
    X server already running on display
    xfce4-session: error while loading shared libraries: libffi.so.6: cannot enable executable stack as shared object requires: Permission denied
    Can you help me with this?

  • Jarno Tuimala kirjoitti:

    @webera: You say that sourcing data in doesn’t work, but does the usual command, e.g., data(animals, package=”cluster”) work instead? If not, I’m slightly out of suggestions.

    I’ve actually more or less switched to using R Console, although it contains an older version (3.1) of R.

  • Jarno Tuimala kirjoitti:

    @Sreenesh: If you check the contents of the path /usr/bin or /usr/local/bin, does either of them contain the file ’R’? If yes, you could try to run it with .\R .

  • Jarno Tuimala kirjoitti:

    @Jon: It appears there was a bug in Debian related to libffi earlier, but it was already patched in 2014. A good starting point for more information is googling the actual error message, which turns out, e.g., this: https://github.com/corbinlc/GNURootDebian/issues/42. I haven’t had much success with X Server myself, so I can’t really offer that much help.

  • zcatav kirjoitti:

    Please use as base system GNURoot Debian (https://play.google.com/store/apps/details?id=com.gnuroot.debian). It has backported repos. After simply installing (like an android app) you can install R with command of ”apt-get -t jessie-backports install r-recommended”.
    Then you can install xserver xsdl to android to use x display.

  • What’s Going down i’m new to this, I stumbled upon this I’ve discovered It positively helpful and it has helped me out loads.
    I’m hoping to give a contribution & help other users like its aided me.
    Great job.


Sähköpostiosoitettasi ei julkaista. Pakolliset kentät on merkitty *