Traceplot(fit) crashes R32 but not R64 with Error: `predicate` must be a closure or function pointer



I’m not sure what has changed, but traceplot(fit) is now throwing an error where it wasn’t before (and crashing R!). Any ideas? This code works in R64 but not in R32!

Windows 10
R version 3.5.0
RStudio 1.1.444
rstan 2.17.3

stan_pars <- c('medb0raw', 'medd1raw', 'slowb0raw', 'slowd1raw', 
               'chem1fast', 'chem1med', 'chem1slow', 'chem2fast', 'chem2med', 'chem2slow')

print(fit, stan_pars)
stan_par(fit, stan_pars[[2]]) # look at misbehaving parameters

# pairs plot to show correlation
temp <- pairs(fit, pars=stan_pars)

# diagnostic plots to check convergence 
some_vars <- stan_pars
temp <- traceplot(fit, pars=some_vars) 
Error: `predicate` must be a closure or function pointer


I think you have another function named traceplot that is masking the rstan one. Does

temp <- rstan::traceplot(fit)



Good suggestion! Sadly it doesn’t work. There is no warning about another traceplot in my loaded packages either.


What output does traceback() give if run immediately after the call to traceplot?


I’m not sure how to get this. When I called traceplot(), I get the error message and R hangs. If I abort R using the red button, I get the Terminate R dialogue, and then RStudio R Session has stopped working and I have to close the program. I tried debug()

# diagnostic plots to check convergence 
some_vars <- c('medb0', 'meda1', 'slowb0', 'slowa1', 
+                'chem1fast', 'chem1med', 'chem1slow',
+                'chem2fast', 'chem2med', 'chem2slow' )
temp <- rstan::traceplot(fit, pars=some_vars) + labs(title=setname) # crashes in 32-bit R!
debugging in: rstan::traceplot(fit, pars = some_vars)
debug: {
Browse[2]> n
debug: standardGeneric("traceplot")
Browse[2]> n
Error: `predicate` must be a closure or function pointer


traceplot() calls stan_trace() which in turn calls ggplot2::facet_wrap() (if pars is of length > 1, which it is here.) This thread: talks about issues with facet_wrap() and the same error message. Can you try calling traceplot() with only one of the parameters and see if the issues persists?

It’s also odd that this happens under differing versions of R, do you have different versions of rstan/ggplot installed on these different versions of R?


Yes no crash when some_vars only has one entry, so it may well be a bug in facet_wrap().


Maybe try reinstalling ggplot2? Either the CRAN version, or the development version? If neither work, there seems to be a pending PR to fix it: and you could go and install the “fixed” version via devtools:install_github("AdeelH/ggplot2") (I’m not sure I would recommend this for long term use though)


I think I’ll just use 64-bit R for now. I have a project which requires 32-bit (uses a 32-bit Fortran DLL) but I’m not working on it at present.