stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.03k stars 264 forks source link

Can't load data from calling environment #690

Open stephenll opened 4 years ago

stephenll commented 4 years ago

Summary:

Please provide a short summary (no more than a sentence or two).

rstan can not load data directly from the calling environment.

Description:

Describe the issue as clearly as possible.

Using the option in stan() to load the data directly from the environment rather than passing a list in does not work. I received Exception: variable does not exist error. I was able to pass in the data directly as a list and that worked.

Reproducible Steps:

Please report steps to reproduce the issue. If it's not possible to reproduce, please include a description of how you discovered the issue.

If you have a reproducible example, please include it.

fit <- stan(model_code = code)

Current Output:

If applicable, any relevant output from RStan.

Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) : 
  Exception: variable does not exist; processing stage=data initialization; variable name=J; base type=int  (in 'modelf019580b27bf_10cdc817017e119334b16bfc660115b2' at line 3)

Expected Output:

If applicable, the output you expected from RStan.

RStan Version:

The version of RStan you are running (e.g., from packageVersion("rstan"))

> packageVersion("rstan")
[1] ‘2.19.2’

R Version:

The version of R you are running (e.g., from R.version.string)

> R.version.string
[1] "R version 3.6.1 (2019-07-05)"

Operating System:

Your operating system (e.g., OS X 10.11.3)

OSX 10.14.6

At my company we can replicate all of this on windows 10 with the latest release versions of R, RStudio, Rtools, rstan, etc...

bgoodri commented 4 years ago

@jgabry Can you fix this? It got broken by the thing that fixed the case where the user had a symbol in the data block named i.

jgabry commented 4 years ago

I can try, but I don't see how going from sapply to a loop would break that (that's the only change in that PR https://github.com/stan-dev/rstan/pull/655/files). Any idea why that change causes this?

Also thanks @stephenll for reporting this!

bgoodri commented 4 years ago

I think the sapply changes the environment in which the parsing function is called.

On Mon, Nov 4, 2019 at 8:17 PM Jonah Gabry notifications@github.com wrote:

I can try, but I don't see how going from sapply to a loop would break that (that's the only change in that PR https://github.com/stan-dev/rstan/pull/655/files). Any idea why that change causes this?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/690?email_source=notifications&email_token=AAZ2XKQ7R7LC25KZPINFJ4TQSDCT3A5CNFSM4ISBLZQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDBIUCA#issuecomment-549620232, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKUQEJ43T3XAKC4XKNTQSDCT3ANCNFSM4ISBLZQA .

jgabry commented 4 years ago

Ah ok, thanks.

jgabry commented 4 years ago

Changing inherits=FALSE to inherits=TRUE in the call to dynGet here

https://github.com/stan-dev/rstan/blob/4f809a092c1f2b42ca35236aab80323261e7dd66/rstan/rstan/R/misc.R#L1612-L1617

seems to fix the problem. But presumably it was FALSE before for a reason. Any unintended consequences to changing it that you can think of?

bgoodri commented 4 years ago

I can't remember

On Tue, Nov 5, 2019 at 12:56 PM Jonah Gabry notifications@github.com wrote:

Changing inherits=FALSE to inherits=TRUE in the call to dynGet here

https://github.com/stan-dev/rstan/blob/4f809a092c1f2b42ca35236aab80323261e7dd66/rstan/rstan/R/misc.R#L1612-L1617

seems to fix the problem. But presumably it was FALSE before for a reason. Any unintended consequences to changing it that you can think of?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/690?email_source=notifications&email_token=AAZ2XKWCA7VMLB6GOLQJ3Z3QSGXVFA5CNFSM4ISBLZQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDDWWMQ#issuecomment-549940018, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKVRLRE5ESYJRPQ7YEDQSGXVFANCNFSM4ISBLZQA .