Recently I have been running R from my Android phone. There are some apps on the Google Play Store that seem to let you emulate R, or connect to a remote version. Instead of doing that, I have been running R directly off my phone using the terminal.
I told Dr Hua Kiefer about it, but she wasn’t so impressed:
Why bother with this at all?
Usually I am not far away from my desk and my reliable computer. Do I really need to run it from my phone? What is the added benefit? There are a few reasons
- It’s cool
- Having R with you is handy, you can
- Look up stats on the fly (no dealing with clunky UI if data API available)
- Create custom plots on the fly
- Run simulations on the go
- With Emacs you can
- Edit text files wherever you are
- Hone your Emacs text editing skills
Since I’ve got my phone with me most times, now can have R with me most times. That makes me happy.
The default keyboard on my Android Phone is good for making good Tweets or sending text messages but not good for editing files. I found two solutions:
Following helpful suggestion online I installed the Hacker Keyboard. This replaced my puny keyboard with a much more robust version.
As good as the Hacker Keyboard is I also bought a little portable Bluetooth keyboard that can pair with my phone. The version I bought is nice and compact. The only downside is the “t” and “v” keys are a little smaller to accommodate the joints where the keyboard folds. That means I tend to miss those keys if I don’t push them hard enough. I think I’ll get used to it and adapt.
I usually use the Rstudio IDE, but as far as I know it is not available on mobile. Fortunately Termux comes with Emacs readily available. After installing it I fired it up and in short order had my first program:
I used to use Emacs years ago, mostly for SAS code. As I haven’t written much SAS code lately I haven’t used Emacs much.
Messing around over the past few days I have begun to recall the Emacs that I forgot. It’s a joy to work with, reminding me of simpler times.
Plus it has games:
How to do it
I am afraid this cannot be a comprehensive guide. The steps I took might not work for your particular setup. I had to use a lot of trial and error to get things working.
However, after some searching (starting with this Reddit post: R on the go) I found that staying pretty close to the steps outlined in the Termux Wiki I was able to get things working. There’s still a few places were things are not working (I have trouble installing certain packages from CRAN). But in general things seem to be working pretty well.
What to do with it
Now that I was up an running, what could we do besides play Tetris?
FRED of course, has a nice application. But I find customizing charts on the phone not the best experience. By loading the data into R we can write our own custom script.
library(tidyverse) library(lubridate) quantmod::getSymbols('MORTGAGE30US', src='FRED') df <-data.frame(date=time(MORTGAGE30US),MORTGAGE30US) png(filename='mtg2.png', height=500,width=800) ggplot(data=df%>% filter(year(date)>2009), aes(x=date,y=MORTGAGE30US))+ geom_line(color='dodgerblue',size=1.2)+ theme_minimal(base_size=18)+ theme(plot.caption=element_text(hjust=0))+ geom_hline(linetype=2, color='dodgerblue', aes(yintercept=last(MORTGAGE30US)))+ labs(x='',y='rate %', title='30-year fixed mortgage rate (%)', caption='@lenkiefer Source Freddie Mac') dev.off()
Most of this post was written on my phone via Emacs