stan-dev / stan-dev/rstan

Provide informative error message with mismatch in data=list(...)

Open
#475 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

Summary:

On my system, if data provided through the rstan::stan(..., data=list(...) ) interface do not match the required types in various ways, I get the inscrutible error

trying deprecated constructor; please alert package maintainer
Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) : 
  no valid constructor available for the argument list
failed to create the sampler; sampling not done

This took me a while to discover the true source of the error (the mismatch was not obvious). Best would be if checking was done that could say in which argument the mismatch appears; but it would at least be much better if the error message said something like:

  No valid constructor available for the argument list: are the provided data of the correct form?
Description:

For example, the following code:

scode <- "
data {
 real x[1];
}
parameters {
 real y[1];
} 
model {
 y[1] ~ normal(x[1], 1);
} 
"
fit1 <- stan(model_code = scode, data = list(x=1.0), iter = 10, verbose = FALSE, chains=1) 

results in the error above. Changing to data=list(x=matrix(1.0)) does not work either, but as @bgoodri pointed out below, data=list(x=array(1.0,1)) does work: obvious in retrospect but not at the time.

The same error occurs in other simple situations, like:

Length mismatch:


scode0 <- "
data {
 vector[4] x;
}
parameters {
 real y[4];
} 
model {
 y ~ normal(x, 1);
}
"
fit0 <- stan(model_code = scode0, data = list(x=rep(1.0,3)), iter = 10, verbose = verbose, chains=1)  

Missing variable:

scode4 <- "
data {
 real x[1];
 int K;
}
parameters {
 real y[K];
} 
model {
 y[1] ~ normal(x[1], 1);
}
"
fit4 <- stan(model_code = scode4, data = list(x=1.0), iter = 10, verbose = verbose, chains=1)  
R and RStan Version:
> packageVersion("rstan")
[1] ‘2.17.2’
> R.version.string
[1] "R version 3.4.3 (2017-11-30)"
Operating System:

Debian sid, updated.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the rstan::stan(..., data=list(...)) entry point and reproduce the provided examples for type, length, and missing-variable mismatches. Trace how these inputs reach the constructor error, then make the reported failure identify the data mismatch or argument involved and verify the examples produce informative messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.