Something went wrong, when calling Stan. Check any debug messages for clues, detective. invalid connection

Hi guys, I’m trying to run a map2stan but I keep getting this error:

running command ‘C:/PROGRA~1/R/R-36~1.1/bin/x64/R CMD SHLIB file3764100376c.cpp 2> file3764100376c.cpp.err.txt’ had status 1Error in sink(type = “output”) : invalid connection.
Error in map2stan(alist(log_gdp ~ dnorm(mu, sigma), mu <- a + bR * rugged + : Something went wrong, when calling Stan. Check any debug messages for clues, detective. invalid connection

Here’s the code I’m trying to run:

    map2stan(
      alist(
        log_gdp ~ dnorm( mu , sigma ) ,
        mu <- a + bR*rugged + bA*cont_africa + bAR*rugged*cont_africa ,
        a ~ dnorm(0, 100),
        bR ~ dnorm(0, 10),
        bA ~ dnorm(0, 10),
        bAR ~ dnorm(0, 10),
        sigma ~ dunif(0, 10)
      ), data=dd.trim )

What does this error mean and what do I do?

I am using the data(rugged) dataset from the rethinking package. The code that preceded the error code is:

library(rethinking)
data(rugged)
d <- rugged
d$log_gdp <- log(d$rgdppc_2000)
dd <- d[ complete.cases(d$rgdppc_2000) , ]
dd.trim = dd[ , c("log_gdp","rugged","cont_africa") ]
str(dd.trim)

You need to tell us the part of the message that has error: (including the colon) when you run

example(stan_model, package = "rstan", run.dontrun = TRUE)
1 Like

It does reproduce if you run just one chain and without using options(mc.cores = parallel::detectCores()). Last time I had to recompile from source the package later and everything worked auto-magically. But I am unaware why the trick worked.

1 Like

Hey, thanks for the reply.
I ran that, and it looked like the issue was that my windows username is has spaces in it, eg. “billy bob joe”

So I went and installed R on another computer with a 1 word username and it all worked, but that computer is incredibly slow so I can’t use it.

Is there any way to solve this sad issue so I can use my own computer to run this stuff?

You most likely just need to do

1 Like

Hooray! This works :) Thanks famsquad <3