Set up R/Stan on Amazon EC2

[This article was first published on Christopher Gandrud (간드루드 크리스토파), and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A few months ago I posted the script that I use to set up my R/JAGS working environment on an Amazon EC2 instance.

Since then I’ve largely transitioned to using R/Stan to estimate my models. So, I’ve updated my setup script (see below).

There are a few other changes:

  • I don’t install/use RStudio on Amazon EC2. Instead, I just use R from the terminal. Don’t get me wrong, I love RStudio. But since what I’m doing on EC2 is just running simulations (I handle the results on my local machine), RStudio is overkill.

  • I don’t install git anymore. Instead I use source_url (from devtools) and source_data (from repmis) to source scripts from GitHub. Again all of the manipulation I’m doing to these scripts is on my local machine.

########################################################
# Set up RStudio and JAGS on an Amazon EC2 instance
# Using Ubuntu 64-bit
# Christopher Gandrud
# 16 December 2014
# Partially from http://blog.yhathq.com/posts/r-in-the-cloud-part-1.html
# See yhat for EC2 instance set up
########################################################
# In your terminal navigate to key pair
# ssh -i YOUR_KEYPAIR.pem ubuntu@PUBLIC_DNS
# Get all programs up to date
sudo apt-get update
# Install latest g++ and clang
sudo apt-get install gcc
sudo apt-get install clang
# Install prerequisites for RCurl
sudo apt-get install libcurl4-openssl-dev
# Check that you have the latest R installed
## see also: http://askubuntu.com/a/352438
sudo apt-get update
apt-cache showpkg r-base
# If R is not the latest version add latest PACKAGE_VERSION returned
# from the pervious line to:
sudo apt-get install -f r-base=PACKAGE_VERSION
# Install rJava
apt-get install r-cran-rjava
# Install Stan and rstan
# First find the number of cores
lscpu
# Load r, set cores, and install
R
Sys.setenv(MAKEFLAGS = "-j4")
source('http://mc-stan.org/rstan/install.R', echo = TRUE,
max.deparse.length = 2000)
install_rstan()
# Install other packages I often use
## Dependencies include reshape2, dplyr
pkgs <- c('repmis', 'DataCombine', 'devtools')
install.packages(pkgs)
q()
######## Running Scripts and Downloading Results onto Local ####
# Run a script so that it runs even if the terminal hands up
# sudo nohup Rscript R_SCRIPT_PATH
# Download a file from Amazon EC2 to your local machine
# (current working directory)
# scp -i YOUR_KEYPAIR.pem ubuntu@PUBLIC_DNS:EC2_FILE_PATH .
view raw r_stan_setup.sh hosted with ❤ by GitHub

To leave a comment for the author, please follow the link and comment on their blog: Christopher Gandrud (간드루드 크리스토파).

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)