Dealing with Catalina

Well, I ran the new fix_Mac() now. When I compile and sample it bails with the usual exception. This is what happens next:

foo ← stan_model(‘model.stan’)
fix_Mac(foo)

Error in fix_Mac(foo) :
Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib not found

Well, for me it’s in /Library/... and not Library/?

OK. I changed fix_Mac to look in /Library just now.

Strange. Nothing. It just gives the prompt back.

But does sampling() work after calling fix_Mac?

Simply sampling(foo)?!?

sampling(foo, data = ...

Works.

1 Like

Thank God. And @kevinushey. Possibly the same thing.

4 Likes

Ben, did you change something permanently? I restarted everything (I’m so pissed at this bug now so wanted to make sure), and now it didn’t work… I still get c++ exception (unknown reason) after running fix_Mac() :-(

And now it worked… Sorry. I’m going to bed now - too tired… I’ll check again tomorrow.

Ok, so I’ve restarted and executed 5 times now and it consistently works. Here’s my MWE foo.R (2.4 KB)

1 Like

Hi, I am a novice rstan user and unfortunately upgraded to Catalina prior to seeing this thread.

I am not able to run any models and have no idea where to being other than trying to follow so posts (https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/).

I have no experience with terminal, so was not able to get the above working.

If anyone can help that would be fantastic.

Thanks!

This is my error specifically:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from file2df66e793e62.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/clang7/include/c++/v1/cstdlib:86:
/usr/lo
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file2df66e793e62.cpp 2> file2df66e793e62.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

Run the installer here:

This will unpackage the correct tools and setup the right paths for R 3.6.1 and macOS Catalina.

Then, wait until @bgoodri commits the suggested library path change to rstan devel or use the fix_macOS() function found in the thread.

Thanks for getting back so quickly! I can’t even make a stan model:

stancode_eightschools ← "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; // school treatment effects
theta = mu + tau * eta;
}

model{
target+= normal_lpdf(eta | 0,1); // prior log-density
target+= normal_lpdf(y | theta, sigma); // log-likelihood
}"

mod ← stan_model(model_code = stancode_MR1)

returns error:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from file4acf6e15a0.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/clang7/include/c++/v1/cstdlib:86:
/usr/loca

mod ← stan_model(model_code = stancode_MR1)
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from file4ac518c0d43.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/clang7/include/c++/v1/cstdlib:86:
/usr/loc
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file4ac518c0d43.cpp 2> file4ac518c0d43.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

You compiler toolchain is not setup correctly. Did you install
https://github.com/rmacoslib/r-macos-rtools/releases/download/v3.0.0/macos-rtools-3.0.0.pkg

I did yes, and just re-installed it too to see if a fresh copy worked (it didn’t).

Should I try the steps here:

https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/ ?

I tried them once before but I didn’t get past the xcode installer because it said it was already installed.

Thanks so much!

First try something simpler like

Rcpp::sourceCpp(code = 
'
#include <Rcpp.h>
using namespace Rcpp; 

// [[Rcpp::export]]
double my_sqrt(double x) {
  return std::sqrt(x);
}
')

If that compiles, then do something like

my_sqrt(9)

This RCPP works for me so I suspect my problem is not compiler paths. However, the sampling still does not work even when fix_MAC from post 53

n=1000
x=-log(runif(n))

library(rstan)
source('FixMAC.R')

fitted_model = stan_model(file='pareto_gfi.stan') 
fix_Mac(fitted_model)

stan_data <- list(y=x, N = n, ymin = 0)

stan_fit = sampling(fitted_model, data = stan_data)

and getting:

SAMPLING FOR MODEL 'pareto_gfi' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.002659 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 26.59 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] "  c++ exception (unknown reason)"                
error occurred during calling the sampler; sampling not done

That worked @bgoodri!