"CPP_stanc280" not resolved from current namespace (rstan) error



I am trying to run a model from McElreath’s book model 8.1

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") ] 

m8.1stan <- map2stan( 
                        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 ~ dcauchy(0,2)
                      ) ,
                      data=dd.trim )

I get this error

Error in .Call("CPP_stanc280", model_code, model_cppname, allow_undefined,  : 
  "CPP_stanc280" not resolved from current namespace (rstan)
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.
"CPP_stanc280" not resolved from current namespace (rstan)

I followed these instructions when installing stan

when I run

Sys.getenv("PATH") I get


which I think is correct


[system('g++ -v')  is:

Using built-in specs.
Target: i686-w64-mingw32](http://)

my R version is version.string R version 3.4.0 Patched (2017-05-16 r72687)

The location of the rstan.dll is


any idea what is happening?

When I try to remove rstan with

remove.packages("rstan",lib="C://TOOLS//R-3.4.0patched//library") I get this error:

Error in remove.packages : there is no package called ‘rstan’

Thank you.


You have a mix of RStan versions, possibly due to trying to upgrade RStan while it was already loaded. You need to manually delete the entire C:\TOOLS\R-3.4.0patched\library\rstan folder and then do install.packages("rstan") again.