Scott Akenhead / Jul 03 2019

Create Environment in R with Stan packages (4 cores, 15 Gbytes)

Remix this to get started with R.



The International Year of the Salmon involves projects that require collaboration on analyses by people all over the world. They need an R environment for really, really easy collaboration ... easier than GitHub (sorry about that) and more like Google Docs and Google Sheets. As in simultaneous. As in "I'm having enough trouble moving from Excel to R, so don't make me learn anything else right now, OK? Yes, thank you, I know it's 2019 not 1989, stop saying that."

Plus that R environment has to be protected from breaking as each of about a hundred pieces of Open Source software is updated or is not updated. So the analysis projects have to be in "containers" like Docker (see rocker). But if you think salmon biologists will not be freaked out by "containers in the cloud" then you haven't met one. So that aspect of the R environment has to be something you can ignore and be successful.

So ... ?

So here we are in Nextjournal, and

  1. cloud-based -- so we are all on the same page (literally, figuratively, and virtually all at the same time!) and not subject to the idiosyncracies of my laptop in Nanaimo (Canada) compared to yours in Vladivostok (Russia) compared to hers in Bergen (Norway). So we are in the cloud -- not just because this is 2019 instead of 1989 -- to allow proper sharing.
  2. collaborative -- you can improve my stuff (my notebooks), easy-peasy. For which I will be grateful and honored. And then improve your improvement (take that!) Or re-purpose my stuff (fork, "re-mix")to re-purpose it for your new analysis. My bricks in your cathedral. Our cathedral. Of knowledge.
  3. contained -- and I finally get to the point. This notebook creates an R environment called R_rstan that is (a) more powerful than the default, with 15 Gybtes of random access memory instead of three and with four virtual cores for processing instead of one, and (b) contains the the Stan packages for rigorous (as in publishable) application of models to data. Competing models. Ecological detectives. Suspects, evidence, challenges, predictions, decisions.
  4. Ta-dah! -- rigorous, reproducible, collaborative research. And easy-peasy. More publications, more collaborators, more progress.

Stan language and associated R packages.

See Rstan The R Interface to Stan

The following packages provide the complete environment for Stan users. Date: 2019-07-02. Most of these are "required" by package rstan so do not require separate installation.


also installing the dependencies 'ucminf', 'numDeriv', 'bitops', 'ordinal', 'e1071', 'miniUI', 'zoo', 'RCurl', 'packrat', 'igraph', 'pan', 'jomo', 'classInt', 'units', 'gdata', 'colourpicker', 'DT', 'dygraphs', 'gtools', 'rsconnect', 'shinyjs', 'shinythemes', 'threejs', 'xts', 'ggridges', 'minqa', 'nloptr', 'flexmix', 'Formula', 'lmtest', 'modeltools', 'sandwich', 'brew', 'commonmark', 'praise', 'mvtnorm', 'Brobdingnag', 'globals', 'listenv', 'mitml', 'sp', 'spData', 'sf', 'deldir', 'LearnBayes', 'expm', 'gmodels', 'corpcor', 'tensorA', 'cubature', 'R.cache', 'StanHeaders', 'inline', 'gridExtra', 'RcppEigen', 'RUnit', 'shinystan', 'bayesplot', 'rstantools', 'lme4', 'betareg', 'HSAUR3', 'roxygen2', 'testthat', 'bridgesampling', 'matrixStats', 'nleqslv', 'coda', 'abind', 'future', 'RWiener', 'mice', 'spdep', 'mnormt', 'MCMCglmm', 'ape', 'arm', 'statmod', 'R.rsp', 'checkmate'

  • Succeeded in 2462 seconds (41 minutes) Added something like 1,700 items.
  • Uploading required 41 seconds. "Save R-rstan: Succeeded. 41.267s"
  • Publish. Until it is published, a notebook's environments are only available to runtimes within itself.
  • Exited completely.
  • Then re-entered my notebook "Multi-level Regression for Sockeye Salmon Spawner Abundance."
  • via gear icon in "RUNTIMES" (upper left), from there the triangle in Environment.
  • Searched for "Scott" to find this notebook "Create Environment ..."
  • Selecting that notebook shows you the environment(s) in that notebook, in this case R_rstan.
  • Selected that environment.
  • Tried a one-statement R cell "library(rstan)". The environment for that cell is now marked R_rstan ... scheduling Runner: 71 seconds. Run Cell R_rstan ... Downloading R_rstan: 18 seconds ...
  • ... <brief exposure to existential void> ...
  • Run Cell R_rstan: Succeeded. rstan (Version 2.18.2, GitRev: 2e1f913d3ca3)
  • Woo hoo!

# first, I created a runtime 'R_rstan' with 4 cores and 15 Gbytes. See gear icon "RUNTIMES" upper left.
# then install.packages() as below.
# finally save the environment and apply in other notebooks.
install.packages( c('rstan','rstanarm', 'brms','loo'), dependencies=T, quiet=T);