Category: SAS

Set up RStudio in the cloud to work with GitHub

I love GitHub for version control and collaboration, though I’m no master of it. And the tools for integrating git and GitHub with RStudio are just amazing boons to productivity.

Unfortunately, my University-supplied computer does not play well with GitHub. Various directories are locked down, and I can’t push or pull to GitHub directly from RStudio. I can’t even use install_github() from the devtools package, which is needed for loading Shiny applications up to Shinyapps.io. I lived with this for a bit, using git from the desktop and rsconnect from a home computer. But what a PIA.

Then I remembered I know how to put RStudio in the cloud— why not install R there, and make that be my GitHub solution?

It works great. The steps are below. In setting it up, I discovered that Digital Ocean has changed their set-up a little bit, so I update the earlier post as well.

1. Go to Digital Ocean and sign up for an account. By using this link, you will get a $10 credit. (Full disclosure: I will also get a $25 credit once you spend $25 real dollars there.) The reason to use this provider is that they have a system ready to run with Docker already built in, which makes it easy. In addition, their prices are quite reasonable. You will need to use a credit card or PayPal to activate your account, but you can play for a long time with your $10 credit– the cheapest machine is $.007 per hour, up to a $5 per month maximum.

2. On your Digital Ocean page, click “Create droplet”. Click on “One-click Apps” and select “Docker (1.9.1 on 14.04)”. (The numbers in the parentheses are the Docker and Ubuntu version, and might change over time.) Then a size (meaning cost/power) of machine and the region closest to you. You can ignore the settings. Give your new computer an arbitrary name. Then click “Create Droplet” at the bottom of the page.

3. It takes a few seconds for the droplet to spin up. Then you should see your droplet dashboard. If not, click “Droplets” from the top bar. Under “More”, click “Access Console”. This brings up a virtual terminal to your cloud computer. Log in (your username is root) using the password that digital ocean sent you when the droplet spun up.

4. Start your RStudio container by typing: docker run -d -p 8787:8787 -e ROOT=TRUE rocker/hadleyverse

You can replace hadleyverse with rstudio if you like, for a quicker first-time installation, but many R users will want enough of Hadley Wickham’s packages that it makes sense to install this version. The -e ROOT=TRUE is crucial for our application here; without it, we can’t install git into the container.

5. Log in to your Cloud-based RStudio. Find the IP address of your cloud computer on the droplet dashboard, and append :8787 to it, and just put it into your browser. For example: http://135.104.92.185:8787. Log in as user rstudio with password rstudio.

6. Install git, inside the Docker container. Inside RStudio, click Tools -> Shell.... Note: you have to use this shell, it’s not the same as using the droplet terminal. Type: sudo apt-get update and then sudo apt-get install git-core to install git.

git likes to know who you are. To set git up, from the same shell prompt, type git config --global user.name "Your Handle" and git config --global user.email "an.email@somewhere.edu"


7. Close the shell, and in RStudio, set things up to work with GitHub: Go to Tools -> Global Options -> Git/SVN. Click on create RSA key. You don’t need a name for it. Create it, close the window, then view it and copy it.


8. Open GitHub, go to your Profile, click “Edit Profile”, “SSH keys”. Click “Add key”, and just paste in the stuff you copied from RStudio in the previous step.


You’re done! To clone an existing repos from Github to your cloud machine, open a new project in RStudio, and select Version Control, then Git, and paste in the URL name that GitHub provides. Then work away!

An unrelated note about aggregators:We love aggregators! Aggregators collect blogs that have similar coverage for the convenience of readers, and for blog authors they offer a way to reach new audiences. SAS and R is aggregated by R-bloggers, PROC-X, and statsblogs with our permission, and by at least 2 other aggregating services which have never contacted us. If you read this on an aggregator that does not credit the blogs it incorporates, please come visit us at SAS and R. We answer comments there and offer direct subscriptions if you like our content. In addition, no one is allowed to profit by this work under our license; if you see advertisements on this page, other than as mentioned above, the aggregator is violating the terms by which we publish our work.

Making peace with storytelling and analytics

A number of years ago I was driving home to Alabama for the holidays. Typical of the season the driving was not easy.  It was getting dark early and the traffic was fairly heavy. I had the radio on to pass the time.  A talk show was on and the […]

The post Making peace with storytelling and analytics appeared first on SAS Learning Post.

Need help picking lottery numbers?

What strategy do you use to pick your lottery numbers? Do you suspect that the future winning numbers might be somehow related to the past winning numbers? If so, this blog’s for you! The Powerball lottery jackpot is up to about $1.4 billion – the largest lottery jackpot there has […]

The post Need help picking lottery numbers? appeared first on SAS Learning Post.

R and SAS in the curriculum: getting students to "think with data"

We’re pleased to announce that a special issue of the American Statistician on “Statistics and the Undergraduate Curriculum” (November, 2015) is available at http://amstat.tandfonline.com/toc/utas20/69/4.

Johanna Hardin (Pomona College) and Nick were the guest editors. There are a number of excellent and provocative papers that reinforce the importance of computing using tools such as R and SAS that are likely to be of widespread interest to the community.

Table of Contents

Teaching the Next Generation of Statistics Students to “Think With Data”: Special Issue on Statistics and the Undergraduate Curriculum : Nicholas J. Horton & Johanna S. Hardin, DOI:10.1080/00031305.2015.1094283 (freely available)

Mere Renovation is Too Little Too Late: We Need to Rethink our Undergraduate Curriculum from the Ground Up George Cobb, DOI:10.1080/00031305.2015.1093029 (freely available for a limited period)

Teaching Statistics at Google-Scale: Nicholas Chamandy, Omkar Muralidharan & Stefan Wager, DOI:10.1080/00031305.2015.1089790

Explorations in Statistics Research: An Approach to Expose Undergraduates to Authentic Data Analysis by Deborah Nolan & Duncan Temple Lang, DOI:10.1080/00031305.2015.1073624

Beyond Normal: Preparing Undergraduates for the Work Force in a Statistical Consulting Capstone by Byran J. Smucker & A. John Bailer, DOI:10.1080/00031305.2015.1077731

A Framework for Infusing Authentic Data Experiences Within Statistics Courses: Scott D. Grimshaw, DOI:10.1080/00031305.2015.1081106

Fostering Conceptual Understanding in Mathematical Statistics: Jennifer L. Green & Erin E. Blankenship, DOI:10.1080/00031305.2015.1069759

The Second Course in Statistics: Design and Analysis of Experiments? by Natalie J. Blades, G. Bruce Schaalje & William F. Christensen, DOI:10.1080/00031305.2015.1086437

A Data Science Course for Undergraduates: Thinking With Data: Ben Baumer, DOI:10.1080/00031305.2015.1081105

Data Science in Statistics Curricula: Preparing Students to “Think with Data” : J. Hardin, R. Hoerl, Nicholas J. Horton, D. Nolan, B. Baumer, O. Hall-Holt, P. Murrell, R. Peng, P. Roback, D. Temple Lang & M. D. Ward, DOI:10.1080/00031305.2015.1077729

Using Online Game-Based Simulations to Strengthen Students’ Understanding of Practical Statistical Issues in Real-World Data Analysis: Shonda Kuiper & Rodney X. Sturdivant, DOI:10.1080/00031305.2015.1075421

Combating Anti-Statistical Thinking Using Simulation-Based Methods Throughout the Undergraduate Curriculum: Nathan Tintle, Beth Chance, George Cobb, Soma Roy, Todd Swanson & Jill VanderStoep, DOI:10.1080/00031305.2015.1081619

What Teachers Should Know About the Bootstrap: Resampling in the Undergraduate Statistics Curriculum : Tim C. Hesterberg, DOI:10.1080/00031305.2015.1089789

Incorporating Statistical Consulting Case Studies in Introductory Time Series Courses: Davit Khachatryan, DOI:10.1080/00031305.2015.1026611

Developing a New Interdisciplinary Computational Analytics Undergraduate Program: A Qualitative-Quantitative-Qualitative Approach: Scotland Leman, Leanna House & Andrew Hoegh, DOI:10.1080/00031305.2015.1090337

From Curriculum Guidelines to Learning Outcomes: Assessment at the Program Level by Beth Chance & Roxy Peck, DOI:10.1080/00031305.2015.1077730

Program Assessment for an Undergraduate Statistics Major: Allison Amanda Moore & Jennifer J. Kaplan, DOI:10.1080/00031305.2015.1087331

The Cobb paper (“Mere Renovation is Too Little Too Late: We Need to Rethink Our Undergraduate Curriculum from the Ground Up (Cobb, 2015) “) has an associated discussion with 19 provocative responses plus George’s spirited rejoinder. These materials can be found on the TAS website or individually at http://www.amherst.edu/~nhorton/mererenovation/.

Discussion (and rejoinder):

  • Response from Albert and Glickman: Attracting undergraduates to statistics through data science
  • Response from Chance, Peck, and Rossman: Response to mere renovation is too little too late
  • Response from De Veaux and Velleman: Teaching statistics algorithmically or stochastically misses the point: why not teach holistically?
  • Response from Fisher and Bailar: Who, what, when and how: changing the undergraduate statistics curriculum
  • Response from Franklin: We need to rethink the way we teach statistics at K-12
  • Response from Gelman and Loken: Moving forward in statistics education while avoiding overconfidence
  • Response from Gould: Augmenting the vocabulary used to describe data
  • Response from Holcomb, Quinn, and Short: Seeking the niche for traditional mathematics within undergraduate statistics and data science curricula
  • Response from Kass: The gap between statistics education and statistical practice
  • Response from King: Training the next generation of statistical scientist
  • Response from Lane-Getaz: Stirring the curricular pot once again
  • Response from Notz: Vision or bad dream?
  • Response from Ridgway: Data Cowboys and Statistical Indians
  • Response from Temple Lang: Authentic data analysis experience
  • Response from Utts: Challenges, changes and choices in the undergraduate statistics curriculum
  • Response from Ward: Learning communities and the undergraduate statistics curriculum
  • Response from Wickham: Teaching Safe-Stats, not statistical abstinence
  • Response from Wild: Further, faster, wider
  • Response from Zieffler: Teardowns, historical renovation, and paint-and-patch: curricular changes and faculty development
  • Rejoinder by Cobb

An unrelated note about aggregators:We love aggregators! Aggregators collect blogs that have similar coverage for the convenience of readers, and for blog authors they offer a way to reach new audiences. SAS and R is aggregated by R-bloggers, PROC-X, and statsblogs with our permission, and by at least 2 other aggregating services which have never contacted us. If you read this on an aggregator that does not credit the blogs it incorporates, please come visit us at SAS and R. We answer comments there and offer direct subscriptions if you like our content. In addition, no one is allowed to profit by this work under our license; if you see advertisements on this page, the aggregator is violating the terms by which we publish our work.

5 new SAS Press titles for the new year

Whether your New Year’s resolution is to get SAS certified or to become a more advanced SAS programmer, we’ve got you covered with these upcoming SAS Press books, many of which will be making their bookshelf debut at SAS® Global Forum 2016 in fabulous Las Vegas! The SAS® Programmer’s PROC […]

The post 5 new SAS Press titles for the new year appeared first on SAS Learning Post.

Write in-line equations in your Shiny application with MathJax

I’ve been working on a Shiny app and wanted to display some math equations. It’s possible to use LaTeX to show math using MathJax, as shown in this example from the makers of Shiny. However, by default, MathJax does not allow in-line equations, because the dollar sign is used so frequently. But I needed to use in-line math in my application. Fortunately, the folks who make MathJax show how to enable the in-line equation mode, and the Shiny documentation shows how to write raw HTML. Here’s how to do it.

R

Here I replicated the code from the official Shiny example linked above. The magic code is inserted into ui.R, just below withMathJax().
## ui.R


library(shiny)

shinyUI(fluidPage(
title = 'MathJax Examples with in-line equations',
withMathJax(),
# section below allows in-line LaTeX via $ in mathjax.
tags$div(HTML("
")),
helpText('An irrational number $\sqrt{2}$
and a fraction $1-\frac{1}{2}$'),
helpText('and a fact about $\pi$:$\frac2\pi = \frac{\sqrt2}2 \cdot
\frac{\sqrt{2+\sqrt2}}2 \cdot
\frac{\sqrt{2+\sqrt{2+\sqrt2}}}2 \cdots$'),
uiOutput('ex1'),
uiOutput('ex2'),
uiOutput('ex3'),
uiOutput('ex4'),
checkboxInput('ex5_visible', 'Show Example 5', FALSE),
uiOutput('ex5')
))



## server.R
library(shiny)

shinyServer(function(input, output, session) {
output$ex1 withMathJax(helpText('Dynamic output 1: $\alpha^2$'))
})
output$ex2 withMathJax(
helpText('and output 2 $3^2+4^2=5^2$'),
helpText('and output 3 $\sin^2(\theta)+\cos^2(\theta)=1$')
)
})
output$ex3 withMathJax(
helpText('The busy Cauchy distribution
$\frac{1}{\pi\gamma\,\left[1 +
\left(\frac{x-x_0}{\gamma}\right)^2\right]}\!$'))
})
output$ex4 invalidateLater(5000, session)
x withMathJax(sprintf("If $X$ is a Cauchy random variable, then
$P(X \leq %.03f ) = %.03f$", x, pcauchy(x)))
})
output$ex5 if (!input$ex5_visible) return()
withMathJax(
helpText('You do not see me initially: $e^{i \pi} + 1 = 0$')
)
})
})

Give it a try (or check out the Shiny app at https://r.amherst.edu/apps/nhorton/mathjax/)! One caveat is that the other means of in-line display, as shown in the official example, doesn’t work when the MathJax HTML is inserted as above.

An unrelated note about aggregators:We love aggregators! Aggregators collect blogs that have similar coverage for the convenience of readers, and for blog authors they offer a way to reach new audiences. SAS and R is aggregated by R-bloggers, PROC-X, and statsblogs with our permission, and by at least 2 other aggregating services which have never contacted us. If you read this on an aggregator that does not credit the blogs it incorporates, please come visit us at SAS and R. We answer comments there and offer direct subscriptions if you like our content. In addition, no one is allowed to profit by this work under our license; if you see advertisements on this page, the aggregator is violating the terms by which we publish our work.

Is holiday spending up or down?

I was reading through Deloitte University Press’ 2015 Holiday Spending survey – the results were interesting, but their graph made you jump through mental hoops to understand the data. So of course I used SAS to create a simpler version of the graph, so you’ll have more time for holiday shopping! […]

The post Is holiday spending up or down? appeared first on SAS Learning Post.

Quote confusion: How do quotes and macro work together?

The English language, a mishmash of words from many tongues and with rules that aren’t always consistent, sometimes causes people to stumble when writing quotes. There are numerous humorous websites with examples of incorrectly-used quotes on signs saying things like “Sandwiches Prepared ‘Fresh’,” or “Help ‘Wanted’ – Please ‘inquire’ within”. […]

The post Quote confusion: How do quotes and macro work together? appeared first on SAS Learning Post.