stan-dev / stan-dev/rstan

sampling() fails if an unrecognized option is provided

Open
#681 5 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:

rstan::sampling doesn't seem to reject or ignore invalid options passed through the ... argument.

Description:

If an invalid option is given, it is not ignored but it causes an ugly failure:

> samples <- sampling(model, data=data.input,
                      chains=4, iter=1000, warmup=500, zzz=TRUE)

Error in FUN(X[[i]], ...) :
  trying to get slot "mode" from an object (class "try-error") that is not an S4 object
In addition: Warning message:
In parallel::mclapply(1:chains, FUN = callFun, mc.preschedule = FALSE,  :
  4 function calls resulted in an error

This came up because I have a function that takes a ... argument that gets passed to rstan::sampling, and I had a typo in one of my arguments (which didn't match and got passed to rstan).

Reproducible Steps:

This is enough to see the failure:

model <- stan_model(model_code="
parameters {
  real y;
}
model {
  y ~ normal(0,1);
}
")
samples <- sampling(model, zzz=TRUE)
Expected Output:

Unrecognized options should be ignored and sampling should proceed correctly. It seems that there's code in the optimizing method that checks recognizable names passed through the ... argument, but no such code exists in sampling.

> samples <- optimizing(model, zzz=TRUE)
Error: passing unknown arguments: zzz.
RStan Version:

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

R Version:

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

Operating System:

Your operating system (e.g., OS X 10.11.3): Ubuntu 18.04.3 LTS

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 by reproducing the failure with rstan::sampling(model, zzz=TRUE), then compare its handling of ... with the behavior of optimizing, which already reports unknown arguments. Trace the sampling entry point and verify that an unrecognized option no longer causes the shown error and that sampling proceeds as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.