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

fitting-issues

#1

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

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)


m8.1stan <- 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 ~ 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

"C:\\TOOLS\\R-3.4.0patched\\bin\\x64;c:\\Rtools\\bin;c:\\Rtools\\mingw_32\\bin;C:\\TOOLS\\Rtools\\bin;C:\\TOOLS\\Rtools\\mingw_32\\bin;

which I think is correct

and

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

Using built-in specs.
COLLECT_GCC=c:\Rtools\mingw_32\bin\G__~1.EXE
COLLECT_LTO_WRAPPER=c:/Rtools/mingw_32/bin/../libexec/gcc/i686-w64-mingw32/4.9.3/lto-wrapper.exe
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

C:\TOOLS\R-3.4.0patched\library\rstan\libs\x64

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.


#2

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.