Since I had this problem, I uninstalled R, RStudio, RTools and deleted folders relevant to R in the Documents and AppData folder and did the following;
-
Installed
R-4.05
,rtools40
andRStudio-1.4.1106
-
Setting up RStan
install.packages("devtools")
library("devtools")
install.packages("lme4", repos=c("http://lme4.r-forge.r-project.org/repos", getOption("repos")[["CRAN"]]))
install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
#install.packages("rstanarm" , type = "source") - this had an error hence revert to line below
install.packages("rstanarm")
install.packages("tidyverse")
dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, ifelse(.Platform$OS.type == "windows", "Makevars.win", "Makevars"))
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native -mtune=native",
if( grepl("^darwin", R.version$os)) "CXX14FLAGS += -arch x86_64 -ftemplate-depth-256" else
if (.Platform$OS.type == "windows") "CXX11FLAGS=-O3 -march=corei7 -mtune=corei7" else
"CXX14FLAGS += -fPIC",
file = M, sep = "\n", append = TRUE)
#
M <- file.path(Sys.getenv("HOME"), ".R", ifelse(.Platform$OS.type == "windows", "Makevars.win", "Makevars"))
file.edit(M)
- Next tried running a sample code
library(lme4)
library(rstan)
library(rstanarm)
library(ggplot2)
library(tidyverse)
library(bayesplot)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
Model <- stan_model(model_code = "parameters{real a;} model{a ~ normal(0,1);}",verbose = T)
This gave the following error:
TRANSLATING MODEL '094809b7474d23e9455596535b79e277' FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model '094809b7474d23e9455596535b79e277'.
COMPILING THE C++ CODE FOR MODEL '094809b7474d23e9455596535b79e277' NOW.
OS: x86_64, mingw32; rstan: 2.21.2; Rcpp: 1.0.6; inline: 0.3.17
Error in cleanup_makevar(old) :
argument "RMU" is missing, with no default
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
'C:/rtools40/usr/mingw_/bin/g++' not found
- After searching I did the following to overcome the error above:
remove.packages("withr", lib="~/R/win-library/4.0")
remotes::install_version("withr", "2.2.0")
Model <- stan_model(model_code = "parameters{real a;} model{a ~ normal(0,1);}",verbose = T)
Then encountered a new error:
.
.
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Users/SHANAK~1/AppData/Local/Temp/RtmpGMBKyC/file46e078b57720.dll':
LoadLibrary failure: A dynamic link library (DLL) initialization routine failed.
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
'C:/rtools40/usr/mingw_/bin/g++' not found
Can you please help me to fix this?