Issue:
I'm using a Windows 10 machine with a "self-contained" toolchain (rather than a global install of Rtools) following the instructions here: https://github.com/ContinuumIO/anaconda-issues/wiki/Install-R-Packages. That has been the only way I've been able to get rstan to work in a conda environment. However, what I've noticed are:
The default version of r-stanheaders installed is ahead of r-rstan,
The default version of r-bh installed does not match the version of r-rstan.
The way I've gotten around these issues is to specify a version of r-rstan, r-stanheaders, and r-bh that all seem to play nice together, but that counter to the intent of conda, since it should "just work" when telling conda to install rstan.
Below are the instructions I follow (I tried to make it as minimal a reprex as possible). Note that if I specify r-rstan=2.17, r-stanheaders=2.17, and r-bh=1.66 in my .yml file then everything works fine.
Reprex/instructions:
1. Create an `tmp.yml` file in some working directory:
```yml
name: tmp
channels:
- conda-forge
- r
- defaults
dependencies:
#Some useful instructions for installing R packages via conda on Windows:
# https://github.com/ContinuumIO/anaconda-issues/wiki/Install-R-Packages
# Toolchain (what Rtools usually takes care of)
- m2w64-toolchain
- m2-make
- m2-sed
- m2-zip
- m2-gzip
- m2-tar
- m2-texinfo
- m2-coreutils
#R stuff
- r-base
- r-rstan
- r-stanheaders
- r-bh
```
2. Create the environment:
```
conda env create -f tmp.yml
```
3. Navigate to the environment's `Library` directory and add a `tmp` folder. This is, for some reason, necessary for the toolchain (see the ContinuumIO link). For example, on my computer, this would result in the following folder structure:
```
C:\Users\Trader\miniconda3\envs\tmp\Library\tmp
```
4. Activate the environment:
```
conda activate tmp
```
5. Create a `.Renviron` file. For some reason, I can't change the system variables in an R session (I have been able to do this from RStudio, but I'm trying to reduce the overhead of this example).
```r
R_HOME=C:/Users/Trader/miniconda3/envs/tmp/lib/R
R_LIBS_USER=C:/Users/Trader/miniconda3/envs/tmp/R/library
R_USER=C:/Users/Trader/miniconda3/envs/tmp
```
6. Test that the installation worked properly, start up R:
```
R.exe
```
7. Inside of R, test that the toolchain works:
```r
pkgbuild::has_build_tools(debug = TRUE) #Should return TRUE, and does for me.
```
8. Test that `{rstan}` works. This breaks when I try to fit the model.
```r
library(rstan)
model_text <- "data {
int J; // number of schools
real y[J]; // estimated treatment effects
real sigma[J]; // standard error of effect estimates
}
parameters {
real mu; // population treatment effect
real tau; // standard deviation in treatment effects
vector[J] eta; // unscaled deviation from mu by school
}
transformed parameters {
vector[J] theta = mu + tau * eta; // school treatment effects
}
model {
target += normal_lpdf(eta | 0, 1); // prior log-density
target += normal_lpdf(y | theta, sigma); // log-likelihood
}"
schools_dat <- list(J = 8,
y = c(28, 8, -3, 7, -1, 1, 18, 12),
sigma = c(15, 10, 16, 11, 9, 11, 10, 18))
fit <- stan(model_code = model_text, data = schools_dat)
```
The error from the last line of code:
```r
Error in stan_model(file, model_name = model_name, model_code = model_code, :
StanHeaders version is ahead of rstan version; see https://github.com/stan-dev/rstan/wiki/RStan-Transition-Periods
```
I'm pretty new to conda, but if there is some way I can help, please let me know. I very much appreciate the effort you all have put into developing this package.
Issue: I'm using a Windows 10 machine with a "self-contained" toolchain (rather than a global install of Rtools) following the instructions here: https://github.com/ContinuumIO/anaconda-issues/wiki/Install-R-Packages. That has been the only way I've been able to get rstan to work in a conda environment. However, what I've noticed are:
The way I've gotten around these issues is to specify a version of r-rstan, r-stanheaders, and r-bh that all seem to play nice together, but that counter to the intent of conda, since it should "just work" when telling conda to install rstan.
Below are the instructions I follow (I tried to make it as minimal a reprex as possible). Note that if I specify
r-rstan=2.17
,r-stanheaders=2.17
, andr-bh=1.66
in my.yml
file then everything works fine.Reprex/instructions:
Environment (
conda list
):Details about
conda
and system (conda info
):I'm pretty new to conda, but if there is some way I can help, please let me know. I very much appreciate the effort you all have put into developing this package.