# CmdstanR - Error in validate\_sample\_args

**URL:** <https://discourse.mc-stan.org/t/cmdstanr-error-in-validate-sample-args/16918>\
**Category:** Other\
**Tags:** cmdstanr\
**Created:** [July 23, 2020, 12:33pm UTC](https://discourse.mc-stan.org/t/cmdstanr-error-in-validate-sample-args/16918 "2020-07-23T12:33:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GustafRydevik](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/gustafrydevik/32/1328_2.png) [@GustafRydevik](https://discourse.mc-stan.org/u/GustafRydevik)\
**Post date:** [July 23, 2020, 12:33pm UTC](https://discourse.mc-stan.org/t/cmdstanr-error-in-validate-sample-args/16918/1 "2020-07-23T12:33:42Z")

</div>

Hi all,

While waiting for the rstan issues for windows+R4.0.2 to get resolved, I’ve been trying to work with cmdstan instead,  
and am getting a strange error.  
I can run cmdstan\_model just fine, but when trying to run the $sample() function, it seems I have to specify all parameters, or it fails. Example:

```

seir_stan<-cmdstan_model(file.path(script.path,"SEIR_fitting.stan"))
seir_fit<-seir_stan$sample(seir_stan,data=stan_data,iter_warmup=400,
                           iter_sampling=1000,chains=5,seed=NULL,
                           refresh = NULL,
                           thin=1,max_treedepth = NULL,
                           init=Guesses,parallel_chains =getOption("mc.cores", 1),
                           threads_per_chain = NULL,save_warmup = FALSE,
                           save_latent_dynamics = FALSE,output_dir = NULL)
Error in validate_sample_args(self, num_procs) : 
  Assertion on 'self$adapt_engaged' failed: Must be of type 'integerish' (or 'NULL'), not 'CmdStanModel/R6'.

```

Does anyone have an idea about what’s going on? I can work around by specifying each argument explicitely, but it get’s tedious. It’s v0.0.0.9008 fwiw.

Thanks in Advance,  
Gustaf

Edit: Another similar, but not identical error message after I’ve added all missing default arguments:

```
Error in seir_stan$sample(seir_stan, data = stan_data, iter_warmup = 400, : 
  Assertion on 'parallel_chains' failed: Must be of type 'integerish' (or 'NULL'), not 'CmdStanModel/R6'.
In addition: Warning message:
In seir_stan$sample(seir_stan, data = stan_data, iter_warmup = 400, :
  'cores' is deprecated. Please use 'parallel_chains' instead.

```

The odd thing here is that I haven’t specified a core argument, only parallel\_chains.

---

<div class="post-metadata">

**Author:** ![GustafRydevik](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/gustafrydevik/32/1328_2.png) [@GustafRydevik](https://discourse.mc-stan.org/u/GustafRydevik)\
**Post date:** [July 23, 2020, 12:59pm UTC](https://discourse.mc-stan.org/t/cmdstanr-error-in-validate-sample-args/16918/2 "2020-07-23T12:59:05Z")

</div>

Sorry, all - false alarm. In the first line, I used

```
seir_stan$sample(seir_stan,...)

```

out of habit from using standard functions. This caused the seir\_stan to be assigned to the first missing argument, e.g cores=, and thus the rest of the confusion. It’s running fine now.

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [July 23, 2020, 4:21pm UTC](https://discourse.mc-stan.org/t/cmdstanr-error-in-validate-sample-args/16918/3 "2020-07-23T16:21:16Z")

</div>

No worries! Glad it’s working now. It can definitely take a little while to get used to accessing methods via `$` and not needing to specify the object as the first argument. That’s happened to me too.
