Mangled variable names with rstan::As.mcmc.list interferes with tidybayes

I’m working with the posterior samples from a model fit using RStan. I started my normal routine of using tidybayes to extract posterior samples from the stanfit object and start plotting. However, I ran into an issue with the variable names that come out of tidy_draws() where instead of the expected bracket notation e.g. x[1], I get the results in an unexpected dot notation form e.g. x.1. This mangling of the names does happen when i use dimnames() on the stanfit object.

I hunted for a long time to find the source of the problem, reading the github repo for tidybayes and rstan and I think I found the source of the problem. rstan::As.mcmc.list appears to be the source of the unexpected renaming.

You can compare the outputs from the following

library(rstan)
library(tidybayes)

csvfiles <- dir(system.file('misc', package = 'rstan'),
                pattern = 'rstan_doc_ex_[0-9].csv', full.names = TRUE)
fit <- read_stan_csv(csvfiles)
dimnames(fit)
As.mcmc.list(fit)
tidy_draws(fit)

I’m not sure how to resolve this issue, because it appears to break a lot functionality with tidybayes. For example, this now longer works because the intermediate mcmc.list created by rstan::As.mcmc.list doesn’t have the expected variable names.

gather_draws(fit, z[i, j])

Is this the correct venue to report this or should I take this to the tidybayes github?

Here is fine. I’ll see if I can come up with something that doesn’t break coda.

Thanks Ben!

Here is a link to a similar/identical issue on the tidybayes github that demonstrates a workaround using the`vroom::vroom() function’s .name_repair argument. The workflow passes the list of csv inputs into coda::as.mcmc then coda::as.mcmc.list. Unfortunately, the end result isn’t a stanfit object but that’s the reality of a workaround.