Skip to content

Instantly share code, notes, and snippets.

@christophergandrud
Last active September 15, 2018 19:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save christophergandrud/c01760a65c03f7047df0 to your computer and use it in GitHub Desktop.
Save christophergandrud/c01760a65c03f7047df0 to your computer and use it in GitHub Desktop.
Setup R, RStudio,and Stan on Ubuntu (for Amazon EC2)
########################################################
# 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 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment