Installing RStan in Ubuntu

[This article was first published on The Ubuntu R Blog, 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.

Based on RStan Getting Started

R packages

Assuming you have the most up to date version of R, the following packages need to be installed. This assumes you have the c2d4u PPA available. See here for more information.

  sudo apt-get install r-cran-rcpp r-cran-inline r-cran-rcpp

C++ Compiler

You probably have a C++ compiler installed, but just in case:

   sudo apt-get install build-essential

The “RStan Getting Started” page suggests modifying the C++ compiler optimization level. On my install of Ubuntu, the optimization was set as the page suggested. You can check with:

   grep "CXXFLAGS =" /usr/lib/R/etc/Makeconf

Among the output of grep, you should see:

   CXXFLAGS = -O3 -pipe  -g $(LTO)

If you do not, use your favorite editor to edit “/ust/lib/R/etc/Makeconf” so that the CXXFLAGS line has “-03” as well as everything else that is there.

Install RStan

From within R, run the following commands. You will need to select a mirror, although it shouldn’t actually use it.

   options(repos = c(getOption("repos"), 
    rstan = ""))
   install.packages('rstan', type = 'source')

It is a large download (for R, 2.3 Mb) and will take some time to compile.

Testing RStan

Now that RStan is installed, you can test it with the following code. RStan compiles the model, then runs it. It will take much longer to compile the code than it takes to generate the samples.

To leave a comment for the author, please follow the link and comment on their blog: The Ubuntu R Blog. 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)