Here is a summary of my experiments, as of October 2021. Long story short: I have a fully working R (complete with tidyverse) on my tablet, and I can access it from jupyter (which is not my first choice in general, but is probably appropriate for this platform and my use - I'm not planning to develop on Android, merely to try code snippets etc).
This draws mostly from the present article as well as from How do I install Jupyter notebook on an Android device? , and links therein.
Also, caveat reader: I'm not an expert in Linux, even less so on Android, and my understanding of Python is minimal. Sorry for any mistake or imprecise statement.
Including trial and errors, the whole process took me some 5 hours. Now I know what to do, I'd probably manage in 1 or 2.
Introduction
Android is a linux in disguise, so in principle it is possible to install all or most linux apps. There are, however, several caveats:
- You normally do not have root access to your device (unless it is rooted, which is another can of worms);
- When compiling binaries, they must be compiled for this specific architecture.
For these reasons, you can not always use ordinary .deb or .rpm packages and need to go through a somewhat convoluted route.
Also, it appears that R-studio cannot be installed without root privileges (either because it requires root itself, or because it relies on libraries that cannot be installed by a normal user).
Assuming you do not want to go the root route, you can still manage quite a few things.
You will need some basic familiarity with linux commands (cd, ls, chmod, ln
...), and at least a basic idea of how packages are installed and managed in linux (apt-get
or pkg
), in R (install.packages()
) and in python (pip install
). Also, it will not harm if you know what a compiler is (gcc), and if you realize that some R/python packages rely on compiled code (binaries) that typically resides somewhere else on the system.
Termux
Termux is "an Android terminal emulator and Linux environment app", a portable Linux distro running on Android (more or less).
Unfortunately the version currently on G-play is not the most recent one, so you want to use the f-droid version. So, install f-droid and then, from f-droid, install termux.
Configure termux
You will need basic tools (compiler etc) up and running on termux. This will require installing packages and in turn, you need packages compiled for this platform. In termux, many packages are maintained by "its-pointless" who also runs the relevant repository. So, in termux :
# basic utilities
pkg install curl gnupg
# Configure its-pointless repo
mkdir -p "$PREFIX/etc/apt/sources.list.d/"
echo "deb https://its-pointless.github.io/files/24 termux extras" > "$PREFIX/etc/apt/sources.list.d/pointless.list"
curl "https://its-pointless.github.io/pointless.gpg" | apt-key add
Now you can install more utilities, from its-pointless repo:
pkg install make \
clang \
gcc-9 \
libgfortran3 \
openssl \
libcurl \
libicu \
libxml2
And configure your compiler
setupclang-gfort-9
R !
Still in termux, run
pkg install r-base
At that stage, you should have a working R on your system (although purely text-based, but you can still use an external editor and source()
your scripts).
Something nicer ?
You maybe want a GUI, or more pakages (tidyverse). Shortly, the main problem you will face is that many R packages in linux rely on system libraries, that need to be installed from linux. In principle you should be able to install the full libraries (the binaries as well as the R code) from install.packages()
, that launches gcc
to compile whatever code is needed; but practically, the compilation seems to fail more often than not. Probably the Android gcc has its quirks...
So the general idea will be to install from termux (or its-pointless) repo the R packages you need, or at least the library they rely on. The same is true for python libs, by the way.
Installing R packages
From within R, try to install what you need with the usual install.packages()
command. If something needs to be compiled, it will probably fail. Read carefully the error - eventually you will find a line that says something like "missing libpango.so". This tells you, in this case, that you need to install pango, which happens to belong to the pango package : in termux, run pkg install pango
, then return to R and try again.
Also, updating your packages to the latest version (pkg upgrade all
) will do no harm...
On stack overflow, you will find various references to zlib, libpng, etc... read and interpret the error message.
In one case (R package repr, that needed base64, itself relying on libicu) I had a version issue - one of the termux packages was (incorrectly) requiring an old version of libicuuc (libicuuc.so.68), whereas the same termux had installed libicuuc.so.69 on my system. In this case, the cure was to create a symbolic link in the approriate directory, as follows
ln -s libicuuc.so.69 libicuuc.so.68
.. and the system happily followed the link :-)
By playing around with this, I managed to install tidyverse, as well as IRkernel that is required to establish a connection between R and jupyter. IRkernel needs to be configured from within R: IRkernel::installspec()
VNC
One user at Installing R on Android refers to the possibility of installing VNC, to obtain Rcmdr. I haven't tried.
Jupyter
It is also possible to install jupyter or jupyter-labs (which is not my favourite IDE under normal circumstances, but is probably an appropriate platform on a Android device).
Jupyter is python based, so you will need to play the same game with Python and python packages. Python packages are installed using pip
(from the linux command line), and you will have the same issue with compiled binaries. Fortunately the most tricky python packages are packaged by its-pointless for termux, so here too, you will end up installing quite a few things outside of pip.
Installing R on Android suggests installing ubuntu on top of termux, and then installing jupyter from within ubuntu. I found it unnecessary (How do I install Jupyter notebook on an Android device?)
Termux will need more packages:
pkg install python fftw libzmq freetype libpng pkg-config libcrypt
There are also references to modejs
, liblapack-dev
and libopenblas-dev
, I cannot remember whether they were required or not in the end (or already installed by something else). Also sometimes the relevant code moved out of the dev package to a stable one (so it would be liblapack)
Then, you need to install python stuff. Web sources suggest
LDFLAGS="-lm -lcompiler_rt" pip install jupyter
or/and, depending on the version you want to use
LDFLAGS="-lm -lcompiler_rt" pip install jupyter-lab
and (not required but useful to have in jupyter) :
LDFLAGS="-lm -lcompiler_rt" pip install numpy matplotlib
I'm not sure why we need LDFLAGS...
As previously, some of the "hybrid" packages are best installed from termux, for instance scipy (technically a python package, should be installed with pip install scipy
) is easier to install (or must be installed?) using the termux version, so pkg install scipy
Again, some debugging will be required. Read the pip output, try to find out which package failed to install, see what you can do from termux, try again. Sometimes I found that dropping the LMFLAGS helped (or installing packages one by one), for instance a plain pip install cffi
and pip install pyzmq
worked better than having them installed as dependencies to jupyter. No idea why.
In the end, I launched jupyter (type jupyter notebook
, or jupyter lab
in termux console, copy the url, open in a browser)... only to have R crash on the first command. Back in termux I could see that it was still missing a library somewhere, which I tracked down and installed from termux (I think it was pango, this time).
So in short: Read the Friendly Error Messages !