charlesm93 / example-models

Example models for Stan
http://mc-stan.org/
5 stars 1 forks source link

SetupRTorsten doesn't work #3

Open charlesm93 opened 7 years ago

charlesm93 commented 7 years ago

A user found an error with SetupRTorsten.R.

The error results from the release of rstan version 2.15 and the fact Torsten is currently built in Stan 2.14. I need to update the installation file so that it picks a version of Stan Torsten has been tested with. The packages get installed and loaded. However, when trying to run a stan file, the following error message appears after compilation:

. . .

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created!

. . .
charlesm93 commented 7 years ago

I think I found a fix, which is mildly elegant. I could do something simpler with:

install_version("rstan", version = "2.14.1", repos = "http://cran.us.r-project.org")

but this procedure overwrites the version of StanHeaders the installation script edits to include Torsten. Any way to prevent rstan from doing this?

charlesm93 commented 7 years ago

The following has been tested on mac and produces the desired results:

YamingSu commented 7 years ago

My understanding is that we need to ensure rstan_2.14.1 and its associated StanHeaders_2.14.0 are used together with Torsten. My workaround is below, and works for me.

  1. Install rstan as usual (https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Windows). This will make sure that the necessary dependent packages for rstan are installed. But note that version of rstan_2.15.1 is to be installed as of today (April-26-2017).

  2. I then used your suggested script below to install Torsten. Note that when rstan_2.14.1 is installed at the last step , the dependencies won't get installed as repos = NULL. Otherwise StanHeader_2.14.0 that is edited by Torsten will be overwritten by the latest production version (i.e., StanHeader_2.15.0 as of April-26-2017).

    
    ## Install RStan, with Torsten built inside of it.

Adjust directories to your setting.

libdir <- file.path("C:/Users/XingSu/Documents/R/win-library/3.3") .libPaths(libdir) library(devtools)

Download and edit StanHeaders (version 2.14.0)

install.packages("https://cran.r-project.org/src/contrib/Archive/StanHeaders/StanHeaders_2.14.0.tar.gz", repos = NULL) setwd(libdir) system("git clone https://github.com/charlesm93/stan.git") setwd("stan") system("git checkout torsten-master") setwd(libdir) system("rm -rf StanHeaders/include/src/stan") system("mv stan/src/stan StanHeaders/include/src/stan") system("rm -rf stan") system("git clone https://github.com/charlesm93/math.git") setwd("math") system("git checkout torsten-master") setwd(libdir) system("rm -rf StanHeaders/include/stan") system("mv math/stan StanHeaders/include/stan") system("rm -rf math")

Download rstan 2.14.1 without the dependencies.

install.packages("https://cran.r-project.org/src/contrib/Archive/rstan/rstan_2.14.1.tar.gz", repos = NULL)

charlesm93 commented 7 years ago

Nice! This is a more elegant approach and doesn't require running pkgSetup.R. The repos = NULL argument was what I was missing. I wonder if we can install all dependencies, except StanHeaders when downloading rstan. That would avoid having to install rstan twice.