Bioequivalence and Bioavailability Forum

Main page Policy/Terms of Use Abbreviations Latest Posts

 Log in |  Register |  Search

Back to the forum  2018-06-21 19:52 CEST (UTC+2h)

2016-09-27 19:54
(edited by VStus on 2016-09-28 09:02)

Posting: # 16687
Views: 5,019

 Running R on Android: library(PowerTOST) [R for BE/BA]

Hi to all!

This post is intended to provide step-by-step HOWTO on installation of more-or-less recent version of R (3.2.5, “Very, Very Secure Dishes”) and latest version of PowerTOST package on Android devices.

In fact, most of modern smartphones are packed with quite powerful processors. As example: Samsung Galaxy S4 is approximately 40000 times more powerful than IBM System/360 Model 75J used by NASA to calculate Apollo flights trajectories (compared by Bogo MIPS). Thank's to Moore's law.

Example: R & PowerTOST in X11 via vnc viewer

Before you try: open this post in your Android's device browser, copy-paste of commands into terminal may be more convenient than typing. Check 'keyboard shortcuts' in GNURoot for more easy navigation with cursor keys and 'home' & 'end' buttons.

#Installation of programs from PlayMarket#
Programs to be installed from PlayMarket:
1. GNURoot (don't be confused, rooting is not required)
2. VNC Viewer (any VNC viewer shold work well, in fact, it's posible to connect via VNC from other device in local network).

#Configuring GNURoot#
Launch GNURoot and create Linux environment. I've tried WheezeX, because I'm familiar with Debian/Ubuntu. X means that minimal graphical system is onboard, so graphs could be displayed.
1. Create rootfs: select WheezyX
2. Run rootfs: WheezyX (to be able to install R and other Linux packages, mark 'run as fake root').
Now we are inside Linux console (bash-style):

#Configuring Debian#
Wheezy is an old version of Debian, so the R is outdated (2.5).
1. Adding R-Cran mirror with latest R backported to Wheezy (German mirror is selected by chance):
# echo "deb  wheezy-cran3/" | tee -a /etc/apt/sources.list
# apt-get update
# apt-get install r-base-core r-base-dev

#Dowloading and installing PowerTOST#
PowerTOST as well as most other packages should be installed from source, as only limited number of r-cran packages for R 3.2.5 have been compiled for Wheezy.
1. Download PowerTOST and mvnorm source from r-cran:
# wget
# wget

Successful download should look like this:
2. Install packages into R:
# R CMD INSTALL mvtnorm*

After this step, you should be able to run R with already installed packaged in console mode:
# R
It should be sufficient to run sample size estimations in your pocket. I may be wrong, but it seems that graphical output in console mode is automatically redirected to PDF files.

# Connecting to Linux X11 terminal via VNC Viever
1. Create new connection in VNC Viewer:
Link to VNC server - localhost:1 (or other number - check Linux console on start-up)
Password: "password"
2. Start VNC session.

PS: Performance
I'm not sure that code executed on all possible cores of your ARM processor.
> system.time(pa.scABE(CV=0.36, theta0=0.9, targetpower=0.8, minpower=0.7, design="2x2x4", regulator="EMA"))
user     system    elapsed
218.810  0.410     226.017

Command above was completed in around 3 minutes, thus the smartphone is still significantly slower than by notebook (Core i5), where it took less than minute.
user      system   elapsed
13.68       0.58      14.64

Please let me know if this is interesting/helpful.

Best regards,

Small update: better console navigation is possible with Hacker's keyboard (PlayMarket), as it adds arrow keys and allows navigation of command history.

Disclaimer: use at your own risk!

Edit: Merged with a later post; you can edit your posts for 24 hours. [Helmut]

2016-09-28 11:02

@ VStus
Posting: # 16689
Views: 4,045

 What about iOS

Is it possible to the same but... in an iPhone? :-D

2016-09-28 14:31

@ DavidManteigas
Posting: # 16690
Views: 4,023

 R on iOS - only after jailbreak :(

Dear David,

I'm not using iOS devices, however I've found GNURoot to be available as a package for iOS, but not in AppStore. Thus, possible only after jailbreak.


Berlin, Germany,
2016-09-29 11:05

@ VStus
Posting: # 16694
Views: 3,966

 Generation Handy

Dear VStus,

I must say I'm very impressed :thumb up:!
And of course I feel flattered that some people have the opinion that they can't be without PowerTOST any minute of their life, but has to be in reach for them all the time at all places, wherever they are.

But ...


We (Helmut, Ben and me), the authors of PowerTOST are not liable for any damage, accidents or calamity resulting from the use of PowerTOST on smartphones during traffic, sports, flights take off or touch down, dates with NLYW or other dangerous activities. Be carefull! Especially in combination with alcohol!:party:



2016-09-29 11:16

@ d_labes
Posting: # 16695
Views: 3,939

 Additional disclaimer and plans for future

Dear Detlew,

Thank you! I've actually met a guy who was going to change his smartphone from iOS to Android just to be able to run R on it. It was an interesting experiment indeed.

By the way, bear should also be doable on Android.

» Disclaimer
I would add that in graphical mode, your Android phone may eat battery quite fast, so don't use it on lithium explosions-prone devices like Note 7 :)

2016-09-30 09:19

@ VStus
Posting: # 16696
Views: 3,945

 Additional disclaimer and plans for future


» I've actually met a guy ...

That guy is so crazy that when he came home from Prague in the middle of the night but still managed to spent >2 hours searching online for a way to install R/Linux in iOS. What a maniac! :lol3:

» ... who was going to change his smartphone from iOS to Android just to be able to run R on it.

Well, it's actually change from company's Blackberry, which is a shitty device, to Android. That guy's iPhone is still pretty new so probably won't be thrown out of the window just yet. :-P

By the way, thanks a lot for the information.

All the best,

2016-10-02 21:27

@ VStus
Posting: # 16698
Views: 3,811

 Running R on Android: Notes and Questions

Dear Vstus!

Dziękuję bardzo!
It works perfectly!
Some naive notes:
1. No need to copy # symbol here and later:
» # echo "deb  wheezy-cran3/" | tee -a /etc/apt/sources.list
(I didn't know that, so it didn't work initially)

2. In VNC viewer I need to push middle button to paste some text (not thru right-button menu)

3. Your phone has excellent performance, I need to think about new one (more than 5 minutes for your example using current phone)

4. Every time when I'm starting wheezex, I got a message:

localhost:1 is taken because of /tmp/.X1-lock
Remove this file if there is no X server localhost:1

Each run adds new localhost line (1, 2, 3...)
I'm removing it manually, but is it possible to solve this problem automatically?

Thanks again!

Kind regards,

2016-10-04 21:56
(edited by VStus on 2016-10-05 08:16)

@ mittyri
Posting: # 16699
Views: 3,702

 Running R on Android: correcting VNCserver startup error

Dear mittyri,

» Dziękuję bardzo!
Всегда пожалуйста!

» I'm removing it manually, but is it possible to solve this problem automatically?

More digging is required to solve this issue. It occurs because vncserver and Xsession are not terminated correctly during termination of GNURoot (when clicking to close the GNURoot console window). I've removed these files manually as well.

USER=noroot vncserver -kill localhost:1
(Correct termination of vncserver. It should remove all lock files if vncserver is properly stopped before closing the GNURoot session as it correctly terminates vncserver and Xserver. Insert your display name)

rm /tmp/.X*
(removes X server lock files)

rm ~/.vnc/*.pid
(removes vncserver lock/pid files)
(I'm missing some other place where lock/pid files should be deleted)

There is a possibility to stop vncserver automatically upon exit, but it requires a correct number of screen (working in certain circumstances but not optimal solution)
File should be named ~/.bashrc (correct filename found!) and contain something like this:
trap_exit() {
    USER=noroot vncserver -kill localhost:1
trap trap_exit EXIT

Limitation of this solution:
- exit command should be entered into console always BEFORE closing GNURoot session;
- if display number changes - server should be stopped manually and .bashrc should be corrected.

It should be possible to avoid this bug by addition of automatic removal of messing pid files at startup of GNURoot (before new vncserver is started), but I have not found the startup script yet.

Regards, VStus
Back to the forum Activity
 Thread view
Bioequivalence and Bioavailability Forum |  Admin contact
18,413 posts in 3,912 threads, 1,174 registered users;
online 36 (0 registered, 36 guests [including 25 identified bots]).

Science is built up with facts, as a house is with stones.
But a collection of facts is no more a science
than a heap of stones is a house.    Henri Poincaré

BEBAC Ing. Helmut Schütz