CmdStanR how to find code for sample method

When I run this command:

 fit <- mod$sample(
      data = ds, 
      seed = 123, 
      chains = 1,  
      refresh = 500,
      adapt_delta = 0.975,
      step_size = 0.1

I get this error message:

Error in lapply(X = X, FUN = FUN, ...) : 
  anyNA() applied to non-(list or vector) of type 'closure'

that isn’t very informative for me as it arises from somewhere within the CmdStanR method sample.
Although @Jonah has very helpfully posted the coding for CmdStanR on Github [GitHub - stan-dev/cmdstanr: CmdStanR: the R interface to CmdStan], I can’t find the code for the sample method.

Can someone tell me where it is, please?

Maybe there should be checks for data types.


EDIT: Ari beat me to it :)

That function would be here: cmdstanr/model.R at master · stan-dev/cmdstanr · GitHub

Most arguments look good to me, the only think that could be causing issue is ds. Is it a list?

Try running cmdstanr::write_stan_json(ds).

1 Like

Many thanks for such a quick response.

A good second place! I will try what you suggest. Thanks.