Array of matrices in Rstan

I want to input in the data block in rstan an array of matrices (3 matrices 147x5, 281x5, 407x5). However, the matrices have different dimensions (in particular different length). How do I specify an array of matrices in data block of Rstan? Otherwise I get this error message because I do not specify the length well so reads the observations not available as missing.

Error in data_list2array(x) : all elements of the list should be numeric

It is not possible to specify an array of matrices with different dimensions in R.
(search for “ragged array” in the Stan Reference)

Thank you! It is very helpful

I also get this error when I’m trying to write out data using stan_rdump because I have a reference to the top-level object. I got confused because I was also trying to write out an array of matrices, but that turned out not to be the problem.

If anybody else gets this error here is the code I use to resolve it:

stan_data_vars = names(stan_data)
for (parameter_name in stan_data_vars) {
    assign(parameter_name, stan_data[[parameter_name]])
}
stan_rdump(stan_data_vars, file="c:/tmp/stan_data.data.R")