New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package Request: R (r-base) #250

Open
tomtom opened this Issue May 4, 2016 · 101 comments

Comments

Projects
None yet
@tomtom

tomtom commented May 4, 2016

Several users of GnuRoot Debian reported that R works on arm. Currently there is no other way to run R on Android.

@dm319

This comment has been minimized.

dm319 commented Nov 27, 2016

this would be great!

@muyang

This comment has been minimized.

muyang commented Dec 2, 2016

I find one way to install R.
(1) install Fedora
see https://nmilosev.svbtle.com/fedora-on-nonrooted-android-phones-2016-update
(2) install R
yum install R
*(3) install KDE
yum|dnf install @kde-desktop

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented Feb 18, 2017

Umm https://github.com/its-pointless/gcc_termux
I actually have an experimental build of R in termux.

@namdnguyen

This comment has been minimized.

namdnguyen commented May 8, 2017

@its-pointless thanks for sharing this! Could you describe the installation process a bit more? I tried extractions the files and then modifying the executive files permissions, but I get an error that R can't load libiconv.so.2. Should I be installing it differently?

@Grimler91

This comment has been minimized.

Collaborator

Grimler91 commented May 8, 2017

@namdnguyen follow the instructions in @its-pointless's readme instead, or look at the detailed steps isaacullah provided in this thread.

With this, you can install it as a normal package with packages install r-cran and get updates.

@namdnguyen

This comment has been minimized.

namdnguyen commented May 8, 2017

@Grimler91 Thank you for the quick reply! I was able to install r-cran with isaacullah's instructions. However, I am still having some trouble getting R to run. I still get the same message, which I'll include below.

CANNOT LINK EXECUTABLE: could not load library "libiconv.so.2" needed by "/data/data/com.termux/files/usr/lib/R/bin/exec/R"; caused by library "libiconv.so.2" not found

I've tried uninstalling and reinstalling iconv to see if that would help, but it doesn't. Any ideas on what I could try next? Am I skipping a necessary step from the README without realizing it?

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 8, 2017

I will fix it later today ... to compile R needs a more functioning libiconv to compile than is in libandroid-support
Thought i made sure it was functioning.

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 8, 2017

wait if its asking for that lib that means the executable is the old version

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 8, 2017

no wait its arm version that is the problem my mistake

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 8, 2017

@namdnguyen

This comment has been minimized.

namdnguyen commented May 9, 2017

Thank you. I copied that to $PREFIX/lib and renamed it to libiconv.so.2 and that message went away, but then it gave a similar message and said that mempcpy was missing.

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 9, 2017

Oh im about deal with that. Its due to differences between devices since you kind of have to build this on device.

A work around is to find a lib with that has that symbol
On your device do
nm -A -D /system/lib/lib*.so | grep mempcpy
A lib with T memcpy is what you want then
LD_PRELOAD=/system/lib/libTHELIB.so R

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 9, 2017

Also if you haven't set TMP variable it will complain about not being able to create R_TempDir
...

@namdnguyen

This comment has been minimized.

namdnguyen commented May 9, 2017

Oh ok, no rush. I really appreciate how incredibly responsive you've been. I will wait.

I did try out the workaround you mentioned. I wasn't able to find any libs with mempcpy, but there were a lot with memcpy without the "p".

@namdnguyen

This comment has been minimized.

namdnguyen commented May 10, 2017

@its-pointless just to confirm, R is working for me now after the latest update. Thank you so much for your contributions! I now have R and ledger on my phone.

@wickx

This comment has been minimized.

wickx commented May 19, 2017

hi, @its-pointless, thanks for this. being able to run R on termux is fantastic.
after adding the link to the sources.list, running and update and then

packages install r-cran

the installation was really easy. unfortunately, when i try to launch R, i get this error message:

CANNOT LINK EXECUTABLE: library "libicuuc.so.59" not found page record for 0x7f81152050 was not found (block_size=64)

any ideas?

thanks again. very useful work. with termux, it's getting to the point where i won't be bound to my laptop anymore. if i could only get R to work... :)

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 19, 2017

apt install libicu should be enough i will add dependency

@wickx

This comment has been minimized.

wickx commented May 19, 2017

f****** brilliant!

it's working. just did a quick install of quantmod, quandl, etc in R. couldn't be happing. it's the latest version of R as well.

i had been messing around with GNURoot Wheezy but this is far superior to anything else out there.

if anyone is wondering how to get R working on android. follow these steps:

  1. install termux
  2. edit your sources.list, by adding the link to the its-pointless repo (see above)
  3. add the key (i didn't bother)
  4. run an update: apt-get update
  5. install this lib: apt install libicu
  6. wait
  7. and finally: packages install r-cran

and you'll be good to go. thanks a lot for this, @its-pointless. this is definitely better than any of the other suggestions online. and i'm glad to see people contributing to termux development, it's a game-changer

@namdnguyen

This comment has been minimized.

namdnguyen commented May 19, 2017

I'm having trouble installing the Rcpp package. I get this error message.

api.cpp:39:18: fatal error: 'execinfo.h' file not found #include <execinfo.h>

Does anyone have any tips or ideas?

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 19, 2017

Android isn;t defined as an option but its easy to add defined(__ANDROID__).
https://github.com/its-pointless/gcc_termux/tree/master/R-patches
i will be putting any patches needed for r stuff there.

@wickx

This comment has been minimized.

wickx commented May 23, 2017

just another update for anyone who's having issues with R on termux. there are a lot of additional packages you need to install within termux itself, make sure you do

packages install clang
packages install libgfortran

amongst others (cant remember all of them). then, when you're in R itself, and you try to install quantmod (for instance)

install.packages('quantmod')

you'll get an error message that the gfortran command can't be found (even though you've installed libgfortran). in tht case, navigate to the

/usr/bin

directory and run this command

cp gfortran-6 gfortran

i have no idea if you're meant to do tht (??) but making a copy of this file with a title tht R recognises worked for me! i can pull financial data through quantmod and quandl and plot it inside a pdf. very happy. now i just have to figure out the equivalent of 'gnome-open' in termux, so tht i can open pdfs directly from the terminal...

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 23, 2017

yeah i probably should of added more documentation.
First thing install gcc-6 should install libgfortran. but if its not listed as a dep thats my fault.

Second point because clang is the default and gcc was removed i setup a script called setupclang and setupgcc-6 to switch between those 2 compilers. It also switches aarch64-linux-android-clang to be a symlink to gcc because of the way python configuration is set linking is sometimes done with aarch64-linux-android-clang not just just $CC. I should probably document it more but i honestly thought no one is going to use it but me so i stopped caring...
anyway if you have any further suggestions im all ears.

@wickx

This comment has been minimized.

wickx commented May 23, 2017

i'll use it! most definitely. i couldn't be happier right now. i just think a lot of people aren't aware tht this exists yet. all the various dependencies aside, getting R on android now basically comes down to installing termux and running one command.
and considering how much i use R in my day to day job, this is really invaluable. thanks.

@namdnguyen

This comment has been minimized.

namdnguyen commented May 26, 2017

Yes, I will second what @wickx said. It's been so helpful for me to have R available on my phone. I'm currently working on getting the tidyverse packages installed. Some of the packages installed (thanks to Rcpp and the gcc-6 compiler), but I think that others (such as stringi) require some fixes in the scripts to fix the shebang with termux-fix-shebang, and installing from source.

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 26, 2017

Yeah issue with stringi is that it uses libicu-dev which needs cxxflags -std=c++11 to work if i remember correctly. Quickest solution is to use command setupgcc-6, build and install stringi then switch back to via setupclang .
i will get a patch up in a bit.

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented May 26, 2017

Also
export CONFIG_SHELL=$PREFIX/bin/sh
helps.

@cptrodolfox

This comment has been minimized.

cptrodolfox commented May 31, 2017

Hello,
I am having problems to install r-cran when I try to use packages install r-cran I get the output unable to locate package r-cran. I have installed the repository and even I have installed libicu.
Thank you in advance,

@wickx

This comment has been minimized.

wickx commented May 31, 2017

hey cptrodolfox, i'm going to use emacs in this example because tht's the text editor i use. feel free to use another. to install emacs, it's

packages install emacs

then, enter the following command to edit your sources.list file, this is the file tht determines what repositories you access when you do an install or update command

emacs $PREFIX/etc/apt/sources.list

once inside the file, move your cursor to the bottom of the file, and paste this line

deb [trusted=yes] https://its-pointless.github.io/files/ termux extras

once you've done that, hit ctrl+x ctrl+s to save and then ctrl-x ctrl+c to exit emacs. after you've exited emacs, run these commands

packages update
packages install r-cran

and R should be installed. to launch R, just type the capitalised letter R on the command line and hit enter.

you'll prolly encounter more issues inside R once you start using it. report back what they are and i should be able to help you, as i currently have R running pretty flawlessly.

@cptrodolfox

This comment has been minimized.

cptrodolfox commented May 31, 2017

Hi wickx,
I have already have done that adding the repository and the key, and done the apt-get update. But, when I try packages install r-cran, It does not locate the package. It hits both repository the main termux and its-pointless one.
Thank you in advance

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented Sep 6, 2017

do you have libgfortran4 not installed?
is the libgfortran.so symlink in $PREFIX/lib missing?

@coolmate6

This comment has been minimized.

coolmate6 commented Sep 7, 2017

Yes i have libgfortran4 installed. In my lib directory i see :
libgfortran.so.3 libgfortran.so.4.0.0
libgfortran.so.3.0.0 libgfortran.spec
libgfortran.so.4

You are right there is no symlink in $PREFIX/lib in my system. Can you advise which version of the libgfortran i should create a symlink with ?

Tks.

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented Sep 7, 2017

with libfortran.so.4.0.0

@coolmate6

This comment has been minimized.

coolmate6 commented Sep 7, 2017

Excellent and thank you very much. All working now. Cheers.

@starlinq

This comment has been minimized.

starlinq commented Nov 19, 2017

After installing r-cran package and trying to run as R, got the following message:
CANNOT LINK EXECUTABLE "/data/data/com.termux/files/usr/lib/R/bin/exec/R": library "libopenblas.so" not found Aborted
Any ideas?

@Grimler91

This comment has been minimized.

Collaborator

Grimler91 commented Nov 19, 2017

@starlinq I'm guess that installing openblas will help since libopenblas.so seem to be missing.

@sdrausty

This comment has been minimized.

sdrausty commented Nov 19, 2017

pacman -S r installs R in Arch Linux in Termux PRoot. R installs with a small r, not a capital one (r-3.4.2-3 installs at present to be precise). See https://sdrausty.github.io/TermuxArch/ for more information about how to install Arch Linux in Termux. Use a capital R to run it:

screenshot_2017-11-19-17-27-46

@starlinq

This comment has been minimized.

starlinq commented Nov 19, 2017

Thank you for the responses. I have solved the issue with command:
pkg install openblas

It is amazing, now I can run R version 3.4.2. I am using a capital letter in command line:
R

screenshot

@bhree

This comment has been minimized.

bhree commented Nov 26, 2017

I can even install IRkernel and have R run on jupyter notebook. Previously I had problem with unavailability of X11 but after last upgrade everything works fine. Thanks to the developers.

kendonB added a commit to kendonB/Rcpp that referenced this issue Jan 6, 2018

Update api.cpp for ANDROID
People are compiling Rcpp on Android so they can work on the bus (and the toilet):

termux/termux-packages#250 (comment)

This patch should help with install Rcpp on that platform. Credit @its-pointless:
https://github.com/its-pointless/gcc_termux/blob/master/R-patches/Rcpp/api.cpp.patch
@kendonB

This comment has been minimized.

kendonB commented Jan 6, 2018

@rfaridi what did you do to get bindrcpp to work?

@anupamsingh81

This comment has been minimized.

anupamsingh81 commented Jan 15, 2018

R installs with relevant instructions in pointless.repo..apt-transport not available
But on running there is seg-fault with invalid permissions

Arch64 with 5.1.1

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented Jan 15, 2018

Invalid permissions?
Whats the exact error?
Are you running in another directory not your home dir?
i will remove https apt stuff from instuctions and scripts as its not longer needed.

@anupamsingh81

This comment has been minimized.

anupamsingh81 commented Jan 16, 2018

Here is the console output when I start R..Have done install 3-4 times with same result..
I am on 5.1.1 64bit,

R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: aarch64-unknown-linux-gnu (64-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.

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.

*** caught segfault ***
address 0x7f8b05abc8, cause 'invalid permissions'

Traceback:
1: .select_device()
2: fun(libname, pkgname)
3: doTryCatch(return(expr), name, parentenv, handler)
4: tryCatchOne(expr, names, parentenv, handlers1L)
5: tryCatchList(expr, classes, parentenv, handlers)
6: tryCatch(fun(libname, pkgname), error = identity)
7: runHook(".onLoad", env, package.lib, package)
8: loadNamespace(package, lib.loc)
9: doTryCatch(return(expr), name, parentenv, handler)
10: tryCatchOne(expr, names, parentenv, handlers1L)
11: tryCatchList(expr, classes, parentenv, handlers)
12: tryCatch({ attr(package, "LibPath") <- which.lib.loc ns <- loadNamespace(package, lib.loc) env <- attachNamespace(ns, pos = pos, deps)}, error = function(e) { P <- if (!is.null(cc <- conditionCall(e))) paste(" in", deparse(cc)[1L]) else "" msg <- gettextf("package or namespace load failed for %s%s:\n %s", sQuote(package), P, conditionMessage(e)) if (logical.return) message(paste("Error:", msg), domain = NA) else stop(msg, call. = FALSE, domain = NA)})
13: library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, warn.conflicts = warn.conflicts, quietly = quietly)
14: doTryCatch(return(expr), name, parentenv, handler)
15: tryCatchOne(expr, names, parentenv, handlers1L)
16: tryCatchList(expr, classes, parentenv, handlers)
17: tryCatch(library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, warn.conflicts = warn.conflicts, quietly = quietly), error = function(e) e)
18: require(pkg, quietly = TRUE, warn.conflicts = FALSE, character.only = TRUE)
19: .First.sys()

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented Jan 16, 2018

iv tried quickly reproducing on a android 5 rom and can't im going to have a closer look. But android 5 libc behavior can often have bugs specific to that rom for a specific manufactored device. For instance if a command line entered is too long it trunicates only using 100 characters sometimes less. Most android 5 roms aren't affected to that degree but some are. I can't gurantee i can fix it even if i can find the cause.

@starlinq

This comment has been minimized.

starlinq commented Mar 28, 2018

After recent updates I cannot run R
$ R
CANNOT LINK EXECUTABLE "/data/data/com.termux/files/usr/lib/R/bin/exec/R": cannot locate symbol "__muldc3" referenced by "/data/data/com.termux/files/usr/lib/R/bin/exec/R"... Aborted

@starlinq

This comment has been minimized.

starlinq commented Mar 28, 2018

Found a solution in another thread:

export LD_PRELOAD=/system/lib/libcompiler_rt.so

@david-macleod

This comment has been minimized.

david-macleod commented Apr 3, 2018

I can install R using the instructions provided, but am struggling to install ANY additional packages. For example

install.packages('zoo')

Results in

sh: make: not found
ERROR: compilation failed for package 'zoo'

Any help would be appreciated.

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented Apr 3, 2018

@david-macleod

This comment has been minimized.

david-macleod commented Apr 3, 2018

So simple! Thank you

@YvesAD

This comment has been minimized.

YvesAD commented Apr 8, 2018

Hello,
Here is the error I have when trying to run R in termux

$ R
CANNOT LINK EXECUTABLE "/data/data/com.termux/files/usr/lib/R/bin/exec/R": cannot locate symbol "catgets" referenced by "/data/data/com.termux/files/usr/lib/R/bin/exec/R"...
Aborted
$

I followed the instructions regarding the libs, reinstalled termux two times already...
Here is the output from temux-info

$ termux-info
Updatable packages: All packages up to date
System information: Linux localhost 3.10.84-13024869 #1 SMP PREEMPT Tue Feb 6 16:13:51 KST 2018 aarch64 Android
Termux-packages arch: aarch64
Android version: 7.0
Device manufacturer: samsung
Device model: SM-T719
$

Thanks for your work.
I am very enthousiast about having a R working on my tablet.
Yours Yves D

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented Apr 8, 2018

Fixed.
Im compiling using omp. Omp that llvm uses uses nl unicode etc. To use with android which doesn't have that android made a nlstubbs.cpp so it would work. Because im using android 8 on this tue libc.so has getcats which is a unicode nl function. So instead of linking the stubbs it linked the real thing from my libc.so on phone.
To fix i just linked libomp.a with the whole archive so the stubbs is used instead and R is not linked
catgets undefined.

@YvesAD

This comment has been minimized.

YvesAD commented Apr 8, 2018

WoW,
that was quick!
It is working now.
Just had to do a "pkg upgrade".

Thanks a lot.
I am physicist mostly teaching math nowadays.
I wanted my pupils to be able to do some serious stats on their phones or tablets
Thanks to you it will be fun next week!
Yours

Yves Delhaye

@BenjaminWolfe

This comment has been minimized.

BenjaminWolfe commented Apr 20, 2018

In R, when I try install.packages('rnormt'), I get the following:

  • installing source package ‘mnormt’ ...
    ** package ‘mnormt’ successfully unpacked and MD5 sums checked ** libs
    gfortran -fpic -g -O2 -c biv-nt.f -o biv-nt.o
    make: gfortran: Command not found
    make: *** [/data/data/com.termux/files/usr/lib/R/etc/Makeconf:183: biv-nt.o] Error 127 ERROR: compilation failed for package ‘mnormt’

I don't know Linux well, but I've followed all the recommendations I could find. (That might be my problem! Maybe I followed conflicting instructions. :D)

I've got the following in $PREFIX/lib:

libgfortran.so
libgfortran.so.3
libgfortran.so.3.0.0
libgfortran.so.4
libgfortran.so.4.0.0

Someone mentioned heading into $PREFIX/bin and copying gfortran-6 to gfortran, but there's no gfortran-6 (or anything looking like gfortran) in $PREFIX/bin.

Any pointers on what to try next? My overall goal was to get tidyverse on my phone (Android One Moto X4), and when it failed I'd decided to walk through the failed dependencies one by one. This one's stumped me.

@its-pointless

This comment has been minimized.

Contributor

its-pointless commented Apr 20, 2018

Its not finding the fortran compiler.
Simple solution is to use the scripts i added to setup different compilers
the command setupclang-gfort-7
This will add a symlink from gfortran-7 to gfortran
It will then find that command when you use R.

@scm-unimelb

This comment has been minimized.

scm-unimelb commented Apr 24, 2018

I have the latest R (3.4.4?) running in termux. I would love to use the 'rtichoke' R console, but it fails to 'find R shared library' (libR.so). I believe this requires building with ./configure --enable-R-shlib before make, and it is a common problem with R Studio users. Is this possible with R for termux?

@dm319

This comment has been minimized.

dm319 commented Jun 15, 2018

Huge thank you to its-pointless. You are helping to spread gnu/linux goodness to all these arm devices!

I have just successfully installed R with library(tidyverse). I added your repository, 'apt install r-base' and then 'apt install gcc-6' and then used the setupgcc6 command to allow installation of library(mnormt).

I copied these instructions for installing stringi/icudata from here, manually downloading the zip file:

@Dieter.Wilhelm The INSTALL documentation for stringi states: If you decide to use our ICU4C bundle then, by default, the ICU data library will be downloaded from one of our mirror servers. However, if you have already downloaded a version of icudt*.zip suitable for your platform (big/little endian), you may wish to install the package by calling: install.packages("stringi", configure.vars="ICUDT_DIR=<icudt_dir>") You can then put the already downloaded zip wherever you'd like and refer to it in <icudt_dir> – danh Oct 17 '17 at 19:11

There is probably a better way to do it, but it worked.

I've also installed neovim, vim-plug and the excellent nvim-R plugin. If you haven't come across it, it is a bit like RStudio for vim.

Now R (and Julia) are pretty much in my pocket. This is terrific and kinda unbelievable! Thanks again!

A pic for inspiration / motivation:

imgp8593_smalld

@ConorIA

This comment has been minimized.

ConorIA commented Jul 8, 2018

If it is of use to anyone who stumbles upon this thread, I've prepared a write-up for a full install of the tidyverse and Nvim-R https://conr.ca/post/installing-r-on-android-via-termux/

@sdrausty

This comment has been minimized.

sdrausty commented Sep 4, 2018

@ConorIA your thread has been shared here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment