Reserved keywords/function names and error reporting

242 views
Skip to first unread message

Richard McElreath

unread,
Jan 24, 2014, 3:44:13 PM1/24/14
to stan-...@googlegroups.com
I had a brief frustration last night with a simple Stan model that had a variable named 'dist' in it. I eventually figured out that 'dist' is a function inside Stan, but the error message was no help. This is the cryptic error message:

TRANSLATING MODEL 'model_code' FROM Stan CODE TO C++ CODE NOW.
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  c++ exception (unknown reason)

The normally nice error messages are one of the things I love about Stan. I like even that "severely misspecified" warning that terrifies everyone. So it was a surprise to get so little info in this case.

Is there some setting I can change to get better feedback in these cases, or is it just something on the to-do list? Or maybe I have something set wrong, so I'm not getting all the information from the compiler that I could be getting?

Bob Carpenter

unread,
Jan 24, 2014, 4:18:06 PM1/24/14
to stan-...@googlegroups.com
Which version of RStan are you using? As of
the current version, if you try to declare "dist"
as a variable, you should see this in both RStan
and CmdStan:


|
EXPECTATION FAILURE LOCATION: file=/Users/carp/temp2/foo.stan; line=2, column=7

real dist;
^-- here


DIAGNOSTIC(S) FROM PARSER:
variable identifier (name) may not be reserved word
found identifier=dist
Parser expecting: <identifier>
|


I believe that was a bug at some point that is fixed
at least as of the 2.1.0 release.

One of my own high-priority to-do items is to mangle
the names of the variables so that there will no longer
be any conflicts with our function names. Not allowing
"dist" as a variable in a model is very bad form on our part!

- Bob
> --
> You received this message because you are subscribed to the Google Groups "stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Richard McElreath

unread,
Jan 24, 2014, 7:18:41 PM1/24/14
to stan-...@googlegroups.com
I'm using 2.1.0. Here's the sessionInfo():

R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstan_2.1.0   inline_0.3.13 Rcpp_0.10.6  

loaded via a namespace (and not attached):
[1] stats4_3.0.2

I just cleaned it out and recompiled, and it still gives me the "c++ exception (unknown reason)" message. 

Here's the minimal script that I used to isolate the issue:

mc <- '
data{
    int N;
    real dist[N];
}
parameters{
    real mu;
}
model{
    dist ~ normal( mu , 1 );
}
'


data
= list( dist=rnorm(100) , N=100 )

mfit
<- stan( model_code=mc , data=data , chains=1 , iter=2000 )

Variable mangling would be wonderful. 

Bob Carpenter

unread,
Jan 24, 2014, 7:58:39 PM1/24/14
to stan-...@googlegroups.com
With your R script, I got the same thing as I got before.

I'm running the standard off-the-shelf RStan.

The only diff I could see in our sessionInfo() is
that you had a later Rcpp version than me. So I
went and installed the later Rcpp and restarted. Same
result as I got before.

At least that means it's not a general RStan problem,
not that it helps solve your issue.

One thought: I'm using the R GUI --- are you using RStudio
or the command-line version of R? If so, can you see if
it works in the R GUI in a new session? Maybe we can
isolate where it's having a problem before asking for
help from those who know R far better than me.

- Bob


Here's my full session:

================================================================
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin10.8.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[R.app GUI 1.62 (6558) x86_64-apple-darwin10.8.0]

[History restored from /Users/carp/.Rapp.history]

> library('RStan')
Error in library("RStan") : there is no package called ‘RStan’
> library('rstan')
Loading required package: Rcpp
Loading required package: inline

Attaching package: ‘inline’

The following object is masked from ‘package:Rcpp’:

registerPlugin

rstan (Version 2.1.0, packaged: 2013-12-27 18:21:10 UTC, GitRev: 548aa7bbbb89)
> mc <- '
+ data{
+ int N;
+ real dist[N];
+ }
+ parameters{
+ real mu;
+ }
+ model{
+ dist ~ normal( mu , 1 );
+ }
+ '
>
> data = list( dist=rnorm(100) , N=100 )
>
> mfit <- stan( model_code=mc , data=data , chains=1 , iter=2000 )

TRANSLATING MODEL 'mc' FROM Stan CODE TO C++ CODE NOW.
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model 'mc' with error message:
EXPECTATION FAILURE LOCATION: file=input; line=4, column=9

real dist[N];
^-- here


DIAGNOSTIC(S) FROM PARSER:
variable identifier (name) may not be reserved word
found identifier=dist
Parser expecting: <identifier>
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rstan_2.1.0 inline_0.3.13 Rcpp_0.10.6

loaded via a namespace (and not attached):
[1] stats4_3.0.2
================================================================

Jiqiang Guo

unread,
Jan 24, 2014, 9:27:52 PM1/24/14
to stan-...@googlegroups.com
I got the same good error message as Bob did. 

I do know which line of code might output the error message of "c++ exception (unknown reason)", but I still cannot explain why.  I will send more info to stan-dev.  

@Richard, could you please let me know the version of your c++ compiler?  Thanks.


Jiqiang 

--
You received this message because you are subscribed to the Google Groups "stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.

Richard McElreath

unread,
Jan 25, 2014, 12:00:24 PM1/25/14
to stan-...@googlegroups.com
Thanks for the help, folks.

@Bob: I use R in Terminal, but I get the same result in the GUI. I don't use RStudio.

@Jiqiang: gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

I just built a clean CmdStan and verified that it works fine---I get the message Bob gets when building form the command line. So this is an RStan issue only it seems.

I do recall some monkeying around with my gcc install, so I could get Radford Neal's pqR to compile with proper thread support. But I can't think how that would affect RStan but not CmdStan.

Anyway, this isn't a big issue. If no one else is experiencing this issue, we can chalk it up to some gremlin in my environment.

Jiqiang Guo

unread,
Jan 25, 2014, 11:01:33 PM1/25/14
to stan-...@googlegroups.com
I guess there is a bug with this version of compiler though we have used gcc 4.2.1 a lot before xcode 5. It could be a rstan problem because R (c code) needs to dynamically load rstan's c++ code, making it different from Stan.

Jiqiang 


--
You received this message because you are subscribed to the Google Groups "stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages