Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data named “i” is overwritten by rstan #654

Closed
jgabry opened this issue Jun 7, 2019 · 2 comments · Fixed by #655
Closed

data named “i” is overwritten by rstan #654

jgabry opened this issue Jun 7, 2019 · 2 comments · Fixed by #655
Labels

Comments

@jgabry
Copy link
Member

jgabry commented Jun 7, 2019

An anonymous user on discourse reported an error that i helped them work around, but is a bug in RStan:

https://discourse.mc-stan.org/t/mismatch-in-dimensionality-stan-is-fixing-the-dimensionality-to-a-number-why/9158

It seems that an integer (probably other types too) named i (lower case) in the list passed to data has its value overwritten when RStan processes/checks the data. The temporary workaround is for the user to just change the name from i to something else.

@jgabry jgabry added the bug label Jun 7, 2019
@jgabry
Copy link
Member Author

jgabry commented Jun 7, 2019

i’ll see if I can sort this out quickly but I may have questions since I haven’t worked much with that part of the RStan code.

@jgabry
Copy link
Member Author

jgabry commented Jun 7, 2019

I don't know why it's happening but it's happening when sampling() calls parse_data():

parsed_data <- with(data, parse_data(get_cppcode(object)))

and specifically when parse_data() uses dynGet():

rstan/rstan/rstan/R/misc.R

Lines 1607 to 1608 in ef3dace

stuff <- sapply(objects, simplify = FALSE, FUN = dynGet,
inherits = FALSE, ifnotfound = NULL)

Here's a minimal working example to trigger it.

// test.stan
data {
  int i;
  vector[i] y;
}
parameters {
 real mu;
}
model {
  y ~ normal(mu, 1);
}
# In R
standata <- list(i = 25, y = rnorm(25))
fit <- stan("test.stan", data = standata, iter = 1, chains = 1)

I'll make a PR shortly that I think will fix this by giving parse_data() a data argument instead of using with(data, ...) and then using mget() instead of dynGet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant