Rstan parsing error

Hi, first post here… For reference I am on a Win10_64 machine.

I have been successfully using stan 2.17.3 for a while now but recently upgraded to R 3.5.1 and while I was at it upgraded rstan to 2.18.1 and Stanheaders 2.18.0.

However I can now no longer get models to compile. For example, if I run the following example model I get

stancode <- ‘data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}’
mod <- stan_model(model_code = stancode, verbose=T)

TRANSLATING MODEL ‘73fc79f8b1915e8208c736914c86d1a1’ FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model ‘73fc79f8b1915e8208c736914c86d1a1’.
COMPILING THE C++ CODE FOR MODEL ‘73fc79f8b1915e8208c736914c86d1a1’ NOW.
OS: x86_64, mingw32; rstan: 2.18.1; Rcpp: 0.12.19; inline: 0.3.15
Error in eval(substitute(expr), data, enclos = parent.frame()) : **
** is.character(repos) is not TRUE

A traceback() gives…

14: stop(simpleError(msg, call = sys.call(-1)))
13: stopifnot(no(“func”) || is.function(func), no(“func”) || is.list(args),
is.character(libpath), is.character(repos), no(“stdout”) ||
is.null(stdout) || is_string(stdout), no(“stderr”) ||
is.null(stderr) || is_string(stderr), no(“error”) ||
is_string(error), is.character(cmdargs), no(“echo”) ||
is_flag(echo), no(“show”) || is_flag(show), no(“callback”) ||
is.null(callback) || is.function(callback), no(“block_callback”) ||
is.null(block_callback) || is.function(block_callback),
no(“spinner”) || is_flag(spinner), is_flag(system_profile),
is_flag(user_profile), is.character(env), no(“timeout”) ||
(length(timeout) == 1 && !is.na(timeout)), no(“wd”) ||
is_string(wd), no(“fail_on_status”) || is_flag(fail_on_status))
12: eval(substitute(expr), data, enclos = parent.frame())
11: eval(substitute(expr), data, enclos = parent.frame())
10: with.default(options, stopifnot(no(“func”) || is.function(func),
no(“func”) || is.list(args), is.character(libpath), is.character(repos),
no(“stdout”) || is.null(stdout) || is_string(stdout), no(“stderr”) ||
is.null(stderr) || is_string(stderr), no(“error”) ||
is_string(error), is.character(cmdargs), no(“echo”) ||
is_flag(echo), no(“show”) || is_flag(show), no(“callback”) ||
is.null(callback) || is.function(callback), no(“block_callback”) ||
is.null(block_callback) || is.function(block_callback),
no(“spinner”) || is_flag(spinner), is_flag(system_profile),
is_flag(user_profile), is.character(env), no(“timeout”) ||
(length(timeout) == 1 && !is.na(timeout)), no(“wd”) ||
is_string(wd), no(“fail_on_status”) || is_flag(fail_on_status)))
9: with(options, stopifnot(no(“func”) || is.function(func), no(“func”) ||
is.list(args), is.character(libpath), is.character(repos),
no(“stdout”) || is.null(stdout) || is_string(stdout), no(“stderr”) ||
is.null(stderr) || is_string(stderr), no(“error”) ||
is_string(error), is.character(cmdargs), no(“echo”) ||
is_flag(echo), no(“show”) || is_flag(show), no(“callback”) ||
is.null(callback) || is.function(callback), no(“block_callback”) ||
is.null(block_callback) || is.function(block_callback),
no(“spinner”) || is_flag(spinner), is_flag(system_profile),
is_flag(user_profile), is.character(env), no(“timeout”) ||
(length(timeout) == 1 && !is.na(timeout)), no(“wd”) ||
is_string(wd), no(“fail_on_status”) || is_flag(fail_on_status)))
8: convert_and_check_my_args(as.list(environment()))
7: callr::rcmd_safe(“config”, “CC”)
6: gsub("\n", “”, callr::rcmd_safe(“config”, “CC”)$stdout)
5: scan_config_for_rtools(debug)
4: has_rtools()
3: pkgbuild::with_build_tools(cxxfunction(sig = sig, body = body,
plugin = plugin, includes = includes, settings = settings,
…, verbose = verbose))
2: cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap("",
model_name, “”);", sep = “”), includes = inc, plugin = “rstan”,
save_dso = save_dso | auto_write, module_name = paste(“stan_fit4”,
model_cppname, “_mod”, sep = “”), verbose = verbose)
1: stan_model(model_code = stancode, verbose = T)

Not sure where I have come unstuck… I followed the rstan (windows) installation guide pretty closely and hence, have the recommended makevars file and compiler flags set. I have Rtools 3.5 installed and I can successfully compile from source…

Any help much appreciated
cheers
Dave

What does

library(pkgbuild)
has_rtools(debug = TRUE)

say?

library(pkgbuild)
has_rtools(debug = TRUE)

Scanning R CMD config CC…
Error in eval(substitute(expr), data, enclos = parent.frame()) :
is.character(repos) is not TRUE

I just unblocked your last post.

I have no idea why Discourse’s spam filter blocked it. We’re getting a lot of spam where spammers cut out bits of a previous post and repost with some ad links, but this one didn’t have any links.

Thanks… that was weird…

If that is from a clean R session, then I think you have hit a bug in the pkgbuild package or callr packages, which rstan is using these days to prevent problems that come up when RTools is installed in weird places. But in this case it seems to be creating a problem for you.

Does callr::rcmd_safe("config", "CC") give the same error message?

Indeed it does…

callr::rcmd_safe(“config”, “CC”)

Error in eval(substitute(expr), data, enclos = parent.frame()) :
is.character(repos) is not TRUE

I am indeed running things from a clean R session. So the issue seems to be in callr::rcmd_safe()? Any obvious workaround? Should I roll back to a previous version?

Thanks for the quick replies by the way…
Dave

Let’s try to figure it out more. It is possible that our instructions messed things up. Does

system2("R", args = "CMD config CC")

work?

Yep.

system2(“R”, args = “CMD config CC”)
c:/Rtools/mingw_64/bin/gcc

OK. If this is my fault, then I don’t see how. Can you file an issue on


saying that

system2("R", args = "CMD config CC")

works but

callr::rcmd_safe("config", "CC")

errors with

Error in eval(substitute(expr), data, enclos = parent.frame()) :
is.character(repos) is not TRUE

when called from pkgbuild::has_build_tools and @bgoodri in case it has anything to do with how rstan is calling it

Ok no problems. I have to duck off (its late arvo in Oz) but will file this tomorrow.

Thanks again for your help…

cheers
Dave

Also, could you try doing

install.packages("https://win-builder.r-project.org/OS3cd95vmm45/rstan_2.18.2.zip", 
                              repos = NULL)
library(rstan)
rstan_options(required = FALSE)

and then try to build a model to see if it lets you past the step where it tries to find CC?

Ok just tried this. no installation issues but ran into this error

library(rstan)
Error: package or namespace load failed for ‘rstan’ in rbind(info, getNamespaceInfo(env, “S3methods”)):
number of columns of matrices must match (see arg 2).

I presume you also saw the workaround posted at the r-lib/callr repo?

I did. I’m glad it wasn’t rstan that caused it and seems like it will be fixed by the next upload of callr. So, let’s work on this error, which I believe I has been reported once but we didn’t figure out the cause or solution. I would start with a

remove.packages("rstan")
install.packages("rstan")

I presume this is to go back to the 2.18.1 build?
done. and Stan now loads…

OK, and it is working as long as your repos option is a character string rather than a list?

Right so I removed rstan and did a clean install using

install.packages("rstan", repos="https://cran.rstudio.com/")

but still get the callr error

What is options()$repos?

[slaps forehead]

setting options(repos = "https://cran.rstudio.com/")

works and models now compile and run normally…

hey thanks for holding my hand on this. I can’t thank you enough.

cheers
Dave

You can do

source("https://install-github.me/r-lib/callr")

to install the fixed version of callr from GitHub and leave your repos option as whatever it was, although options(repos = "https://cran.rstudio.com/") is probably ideal because it redirects to the best mirror.