Stan compiling error


#1

Hi,
I have a problem with compiling rstan after I updated new macOS operating system. I ran the 8-school example code on getting-started-with-rstan and got the error:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from file25277b5520e.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:8:
In file included from /usr/local/clang4/bin/../include/c++/v1/cstdlib:86:
/
In addition: Warning messages:
1: In readLines(file, warn = TRUE) :
  incomplete final line found on '/Users/yang/Documents/RProgramming/8schools.stan'
2: In system(cmd, intern = !verbose) :
  running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file25277b5520e.cpp 2> file25277b5520e.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

For traceback, the stan file is:

// saved as 8schools.stan
data {
  int<lower=0> J;         // number of schools 
  real y[J];              // estimated treatment effects
  real<lower=0> sigma[J]; // standard error of effect estimates 
}
parameters {
  real mu;                // population treatment effect
  real<lower=0> 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
}

And the R code is:

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(file = '8schools.stan', data = schools_dat)
print(fit)
plot(fit)

Can anyone help me out here? Thanks!!!

Operating system: macOS Mojave 10.14
R version 3.5.1


#2

Try first doing

file.rename("~/.R/Makevars", "~/.R/old_Makevars")

#3

I’m sorry. It returns FALSE with the warning message:

Warning message:
In file.rename("~/.R/Makevars", "~/.R/old_Makevars") :
  cannot rename file '/Users/yang/.R/Makevars' to '/Users/yang/.R/old_Makevars', reason 'Permission denied'

#4

OK. I don’t know why you wouldn’t be able to write to your own home directory. Try

file.edit("~/.R/Makevars")

and deleting everything in it.


#5

Yea. It works. Thank you so much.


#6

I’ve just run into the same problem, but am unable to rename the Makevars file or delete the contents of the existing file. Any idea what causes this?

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.14.2

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils    
[5] datasets  methods   base     

other attached packages:
 [1] raster_2.6-7       bindrcpp_0.2.2    
 [3] ggridges_0.5.1     tidybayes_1.0.1   
 [5] rstan_2.18.2       StanHeaders_2.18.0
 [7] tigris_0.7         forcats_0.3.0     
 [9] stringr_1.3.1      dplyr_0.7.6       
[11] purrr_0.2.5        readr_1.1.1       
[13] tidyr_0.8.1        tibble_1.4.2      
[15] ggplot2_3.0.0      tidyverse_1.2.1   
[17] sf_0.6-3           spdep_0.7-9       
[19] spData_0.2.9.4     Matrix_1.2-14     
[21] sp_1.3-1          

loaded via a namespace (and not attached):
 [1] nlme_3.1-137             
 [2] matrixStats_0.54.0       
 [3] lubridate_1.7.4          
 [4] gmodels_2.18.1           
 [5] httr_1.3.1               
 [6] LaplacesDemon_16.1.1     
 [7] tools_3.5.1              
 [8] backports_1.1.2          
 [9] rgdal_1.3-4              
[10] R6_2.2.2                 
[11] DBI_1.0.0                
[12] lazyeval_0.2.1           
[13] colorspace_1.3-2         
[14] withr_2.1.2              
[15] tidyselect_0.2.4         
[16] gridExtra_2.3            
[17] prettyunits_1.0.2        
[18] processx_3.2.0           
[19] compiler_3.5.1           
[20] cli_1.0.1                
[21] rvest_0.3.2              
[22] arrayhelpers_1.0-20160527
[23] expm_0.999-3             
[24] xml2_1.2.0               
[25] scales_1.0.0             
[26] classInt_0.2-3           
[27] mvtnorm_1.0-8            
[28] callr_3.0.0              
[29] rappdirs_0.3.1           
[30] foreign_0.8-70           
[31] rethinking_1.59          
[32] base64enc_0.1-3          
[33] pkgconfig_2.0.2          
[34] rlang_0.2.2              
[35] readxl_1.1.0             
[36] rstudioapi_0.7           
[37] svUnit_0.7-12            
[38] bindr_0.1.1              
[39] jsonlite_1.5             
[40] gtools_3.8.1             
[41] inline_0.3.15            
[42] magrittr_1.5             
[43] loo_2.0.0                
[44] Rcpp_0.12.19             
[45] munsell_0.5.0            
[46] stringi_1.2.4            
[47] yaml_2.2.0               
[48] MASS_7.3-50              
[49] ggstance_0.3.1           
[50] pkgbuild_1.0.2           
[51] plyr_1.8.4               
[52] grid_3.5.1               
[53] maptools_0.9-4           
[54] parallel_3.5.1           
[55] gdata_2.18.0             
[56] crayon_1.3.4             
[57] deldir_0.1-15            
[58] lattice_0.20-35          
[59] haven_1.1.2              
[60] splines_3.5.1            
[61] hms_0.4.2                
[62] ps_1.1.0                 
[63] pillar_1.3.0             
[64] uuid_0.1-2               
[65] boot_1.3-20              
[66] stats4_3.5.1             
[67] LearnBayes_2.15.1        
[68] glue_1.3.0               
[69] modelr_0.1.2             
[70] cellranger_1.1.0         
[71] gtable_0.2.0             
[72] assertthat_0.2.0         
[73] broom_0.5.0              
[74] e1071_1.7-0              
[75] coda_0.19-2              
[76] class_7.3-14             
[77] units_0.6-1

#7

Never mind - I figured it out by looking at this post