Testing R on my Android tablet


So I was recently faced with a tough choice before heading to a field course in Peru: to I take my large, heavy, everyday laptop or take a smaller less powerful computer. The pros of taking my everyday computer is that I am comfortable with how I use it now and I have access to all my files and increased functionality. The cons are that it is large and heavy (~5lbs does not seem like much but, man can I feel a difference) and it cost me $1.5k. I am not sure I want to (1) lug it around with me and (2) risk breaking or losing a very valuable piece of equipment that is essential to my PhD. I plan to do quite a bit of hiking/trekking around and would only feel comfortable if it was on me at all times.

So I started looking for alternatives... simple netbooks and small laptops that were within what I was willing to pay (<$200, still a decent chunk of my stipend). However, I started to realize that I had something with similar enough specs that I could potentially use, my Samsung tablet (SM-P600) I bought during my master's. Its current and previous uses have been watching Netflix and reading/commenting papers, but maybe now it has a new purpose!

I did a lot of googling and browsing many sites (see here, here, and there are many more). I found that I could add something like a virtual Linux machine on my tablet without having to root it. I have tested it a bit and am pleased but the real test will be the field course (so fingers crossed and will report back after the course). For anyone who is interested and for my future reference (because I will surely forget these steps) here are the steps I did which mirror those I found on other sites:

!!!!!!!!! If you follow these steps it is at your own risk. I do not expect anything below will permanently harm a device but I do not take any responsibility for crashed or bricked tablets/phone/devices !!!!!!!!!!!!!

(1) Download both GNURoot Debian and XServer XSDL from the Google play store. I also download QuickEdit for writing code outside of the terminal.

(2) Open GNURoot Debian and run:

apt-get update
apt-get update

(3) Then run the following code to install backports version of R. As of Feb 2018 the most current version of R available is 3.4.3 but I can only get R 3.3.3 on backports (was good enough for me but check here for some potential work-arounds). This takes a while so I would just run this line and let it go.

apt-get install -t jessie-backports install r-recommended

NOTE: for some  packages I wanted in R, I also had to install some other Linux packages and dependencies. I would suggest trying to load the package in R and look at any error outputs to see what dependencies you might need. Below are a couple I have to install for "devtools" and "nloptr." Remember to update in between installing dependancies!

apt-get update
apt-get install pkg-config libssl-dev
apt-get update
apt-get install libnlopt-dev

(4) Install a package in Debian so that you can send any plots or other displays to XServer. There is an example of this where you can have an entire Linux GUI on you tablet but I just wanted a screen where I can send plots to so I installed 'i3'. *People have previously gotten RStudio on their tablet but I haven't gone down that route yet, see here too.

apt-get install i3

I also found that the option for using simple text plots is also very nice in R in the Debian terminal (see NostalgiR).


(5) Now we can work in R! First open XServer XDSL (the first time you open the app it will ask you if you want to download some extra fonts, I clicked 'yes'). You will get a blue screen (see above) with some code that you need to put into the Debian terminal (before you open R). My code is the bottom line:

export DISPLAY=:0 PULSE_SERVER=tcp:1027.0.0.1:4712

Since my tablet allows split screens, this is what I see:


Then launch the i3 package in the Linux terminal (see above): 

i3 &

(6) Now, I open R and make a simple plot. The first time i3 comes on it is a little fussy (I probably just don't have the kinks figured out yet). For the plot to show, you have to 'click' or 'touch' the program to prompt it. Then going back to R just hit enter and you are ready for whatever next steps you want to take.


Plotting is slower than my other computer (which is expected) but it gets the job done! You have to switch between the terminal and XServer app each time you send code to the plotting device (even when using dev.off() in R). Before exiting R, I have found that turning off the graphics devices helps with not confusing the program and XServer:


(7) When you are out of R and completely done with the your time in Debian, turn off i3 by inputting the code below and tapping the XServer app again. 

i3 exit

Then stop XServer via the notifications tab (see above) and go back to the terminal and type:


GNURoot Debian will close, you can closer XServer, and you will be done!


Soooo... about $100 bucks and lots of time later, I had a device that I could enter data, analyse the data, write a report, and create some basic plots (and also create a basic presentation if need be via the PowerPoint app). It was really neat to add this to my tablet and I am excited/scared to learn more about the quirks of using this new functionality. Of course, its uses are limit so I will not be parting with my brick of a laptop anytime soon, but for the field course I am sure that it will be sufficient (yet slow). An extra plus, all of the accessories I bought can also be used on my phone or any Bluetooth and/or USB Micro device if need be.


Anything I missed? Suggestions to improve what I have done? Found other things to work for you? Comments? Questions (which I am unsure I can answer)? Let me know! I will update here and respond as needed!


(1) To 'put' files onto you Debian computer you need to put anything you want in the following file on your Android (I would think it would be similar on other devices):


Go to "Device storage > GNURoot > home" and paste your file into the folder.


Then you can find that file in GNURoot under "/home".

(2) For those that want to make .csv's on the fly, I have only found one app that will let me enter data into a spreadsheet form and save it as a ".csv", WPS Office. This way I can enter data, save it as a .csv, move it into my GNURoot directory, and do some preliminary analyses all on the same device.

(3) I have found that I can attach my 2TB external hard drive that is helpful for carrying around files in general (have yet to test how to access in GNURoot and R). It does require a piece of hardware (A) and an app (B): (A) a OTG cable with power. I choose this one but there are many others out there that have the same capability and could potentially charge your tablet at the same time as powering your external hard drive. The one I have requires external power has 4 USB import locations (one with power for my external and three without for USB flash drives) but does not charge my tablet at the same time. It also works without the power just with the USB flash drives that do not need power. (B) I have only found one app USB Media Explorer that works the way I want it to. It lets me attach ExFAT and NTFS formatted drives - this app is PAID ($3.99) and the only app I have ever actually bought so far - just used my Google Opinion Rewards so it was basically no money out of my pocket. You may have better luck finding and using one of the free apps!

(4) The use of a Bluetooth keyboard and number pad have been very helpful with increasing the functionality of my tablet. I also got a mouse but I have found it to be too cumbersome compared to using my touchscreen. I bought all 3 from Jelly Comb and have been please so far. You might find a better option out there for you. **The number pad's other usages (e.g. "Home" and "End" do not seem to work for me in the word processing app or R, but there is a key combination on the Bluetooth keyboard that works well).

For those of you struggling without a keyboard to recall text in the terminal or R (where you would have hit the up key) you need to click the Volume up button and then hit 'w' on your screen keyboard. Or install an app like Hacker's Keyboard. I also bought a collapsible stand for my tablet but the jury is out on if I like it our not... it does a decent job of getting the screen closer to eye-level but is not made for such a big device and tipping is an issue (see top pic).