VStus
★    

Poland,
2016-09-27 21:54
(2738 d 17:03 ago)

(edited by VStus on 2016-09-28 09:02)
Posting: # 16687
Views: 8,665
 

 Running R on Android: library(PowerTOST) [🇷 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
[image]

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).

[image]
#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):
[image]

#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 http://cran.uni-muenster.de/bin/linux/debian  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 https://cran.r-project.org/src/contrib/PowerTOST_1.4-2.tar.gz
# wget https://cran.r-project.org/src/contrib/mvtnorm_1.0-5.tar.gz

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


After this step, you should be able to run R with already installed packaged in console mode:
# R
[image]
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,
Vstus


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]
DavidManteigas
★    

Portugal,
2016-09-28 13:02
(2738 d 01:55 ago)

@ VStus
Posting: # 16689
Views: 7,095
 

 What about iOS

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

Poland,
2016-09-28 16:31
(2737 d 22:26 ago)

@ DavidManteigas
Posting: # 16690
Views: 7,069
 

 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.

Regards,
VStus
d_labes
★★★

Berlin, Germany,
2016-09-29 13:05
(2737 d 01:53 ago)

@ VStus
Posting: # 16694
Views: 7,014
 

 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 ...

Disclaimer

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:

Regards,

Detlew
VStus
★    

Poland,
2016-09-29 13:16
(2737 d 01:41 ago)

@ d_labes
Posting: # 16695
Views: 6,965
 

 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 :)
Shuanghe
★★  

Spain,
2016-09-30 11:19
(2736 d 03:38 ago)

@ VStus
Posting: # 16696
Views: 7,014
 

 Additional disclaimer and plans for future

Hi,

❝ 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,
Shuanghe
mittyri
★★  

Russia,
2016-10-02 23:27
(2733 d 15:30 ago)

@ VStus
Posting: # 16698
Views: 6,876
 

 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 http://cran.uni-muenster.de/bin/linux/debian  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,
Mittyri
VStus
★    

Poland,
2016-10-04 23:56
(2731 d 15:01 ago)

(edited by VStus on 2016-10-05 08:16)
@ mittyri
Posting: # 16699
Views: 6,801
 

 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
UA Flag
Activity
 Admin contact
22,957 posts in 4,819 threads, 1,639 registered users;
81 visitors (0 registered, 81 guests [including 12 identified bots]).
Forum time: 13:58 CET (Europe/Vienna)

Nothing shows a lack of mathematical education more
than an overly precise calculation.    Carl Friedrich Gauß

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5