{"action":"created","issue":{"url":"https://api.github.com/repos/stan-dev/rstan/issues/204","labels_url":"https://api.github.com/repos/stan-dev/rstan/issues/204/labels{/name}","comments_url":"https://api.github.com/repos/stan-dev/rstan/issues/204/comments","events_url":"https://api.github.com/repos/stan-dev/rstan/issues/204/events","html_url":"https://github.com/stan-dev/rstan/issues/204","id":105634513,"number":204,"title":"Rats example does not work, problem with dimension of x","user":{"login":"josephwb","id":808499,"avatar_url":"https://avatars.githubusercontent.com/u/808499?v=3","gravatar_id":"","url":"https://api.github.com/users/josephwb","html_url":"https://github.com/josephwb","followers_url":"https://api.github.com/users/josephwb/followers","following_url":"https://api.github.com/users/josephwb/following{/other_user}","gists_url":"https://api.github.com/users/josephwb/gists{/gist_id}","starred_url":"https://api.github.com/users/josephwb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephwb/subscriptions","organizations_url":"https://api.github.com/users/josephwb/orgs","repos_url":"https://api.github.com/users/josephwb/repos","events_url":"https://api.github.com/users/josephwb/events{/privacy}","received_events_url":"https://api.github.com/users/josephwb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-09T16:35:12Z","updated_at":"2015-09-09T17:37:03Z","closed_at":null,"body":"Running the example from the [documentation](https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started#example-2-rats) gets:\r\n```r\r\nrats_fit <- stan(file='rats.stan', verbose=FALSE);\r\nCOMPILING THE C++ CODE FOR MODEL 'rats' NOW.\r\nError : mismatch in dimension declared and found in context; processing stage=data initialization; variable name=x; position=0; dims declared=(1); dims found=(5)\r\nfailed to create the sampler; sampling not done\r\n```\r\nPossibly related to https://github.com/stan-dev/example-models/issues/25?"},"comment":{"url":"https://api.github.com/repos/stan-dev/rstan/issues/comments/138986128","html_url":"https://github.com/stan-dev/rstan/issues/204#issuecomment-138986128","issue_url":"https://api.github.com/repos/stan-dev/rstan/issues/204","id":138986128,"user":{"login":"jgabry","id":7796803,"avatar_url":"https://avatars.githubusercontent.com/u/7796803?v=3","gravatar_id":"","url":"https://api.github.com/users/jgabry","html_url":"https://github.com/jgabry","followers_url":"https://api.github.com/users/jgabry/followers","following_url":"https://api.github.com/users/jgabry/following{/other_user}","gists_url":"https://api.github.com/users/jgabry/gists{/gist_id}","starred_url":"https://api.github.com/users/jgabry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgabry/subscriptions","organizations_url":"https://api.github.com/users/jgabry/orgs","repos_url":"https://api.github.com/users/jgabry/repos","events_url":"https://api.github.com/users/jgabry/events{/privacy}","received_events_url":"https://api.github.com/users/jgabry/received_events","type":"User","site_admin":false},"created_at":"2015-09-09T17:37:03Z","updated_at":"2015-09-09T17:37:03Z","body":"Actually the way you had it originally should work because if you omit the data argument it should look for the objects in your global environment. \r\n\r\nI just realized why this error is happening. The code on the wiki page is this:\r\n\r\n    y <- read.table('rats.txt', header = TRUE)\r\n    x <- c(8, 15, 22, 29, 36)\r\n    xbar <- mean(x)\r\n    N <- nrow(y)\r\n    T <- ncol(y)\r\n    rats_fit <- stan(file = 'rats.stan', verbose = FALSE)\r\n\r\nBecause there's a variable `T` in the `rats.stan` file we've defined a variable `T` in the R global environment. In this case `T <- ncol(y)`, which is `T = 5`. If the `data` argument is not a named list (i.e., if it is omitted or if it is a character vector of names) then when `stan` goes to search for the variables it goes and looks for `T` and decides that `T` is `TRUE` rather than the object `T` we created which has a value of 5. \r\n\r\n"}}