# New posterior::extract\_list\_of\_variable\_arrays()

**URL:** <https://discourse.mc-stan.org/t/new-posterior-extract-list-of-variable-arrays/40838>\
**Category:** Interfaces\
**Tags:** posterior-package\
**Created:** [January 17, 2026, 8:14am UTC](https://discourse.mc-stan.org/t/new-posterior-extract-list-of-variable-arrays/40838 "2026-01-17T08:14:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [January 17, 2026, 8:14am UTC](https://discourse.mc-stan.org/t/new-posterior-extract-list-of-variable-arrays/40838/1 "2026-01-17T08:14:14Z")

</div>

Recently people have been refering to @andrjohns’ [post](https://discourse.mc-stan.org/t/rstan-read-stan-csv-throwing-error-with-cmdstan-models-versions-2-35/35665/7) saying

> [@Rstan::read\_stan\_csv throwing error with cmdstan models (versions 2.35)](https://discourse.mc-stan.org/t/rstan-read-stan-csv-throwing-error-with-cmdstan-models-versions-2-35/35665/7):
>
> If the end goal is a named list where each element is an array of posterior samples for a given variable, you could implement the `extract_samples` function for `cmdstanr` and `posterior` as:

github version of `posterior` package has now variant of the code

- existing `extract_variable_array()`, which extracts just one variable, has now argument `with_chains`, with the default value `TRUE` for backward compatibility
- new `extract_list_of_variable_arrays()` extracts all variables, and it works with all posterior object types (no need for the fit object)

These are helpful for extracting arrays of multivariate variables

Pinging also @GabrielR and @Michael_Peck who liked @andrjohns’ solution

edit: added sub-category

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [January 20, 2026, 9:14pm UTC](https://discourse.mc-stan.org/t/new-posterior-extract-list-of-variable-arrays/40838/2 "2026-01-20T21:14:26Z")

</div>

> [@avehtari](#):
>
> github version of `posterior` package has now variant of the code

Awesome!

> [@avehtari](#):
>
> These are helpful for extracting arrays of multivariate variables

+1 to that. This has been super useful in CmdStanPy. It’s also nice to be able to extract just one variable, too.

---

<div class="post-metadata">

**Author:** ![andre.pfeuffer](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@andre.pfeuffer](https://discourse.mc-stan.org/u/andre.pfeuffer)\
**Post date:** [January 25, 2026, 1:13pm UTC](https://discourse.mc-stan.org/t/new-posterior-extract-list-of-variable-arrays/40838/3 "2026-01-25T13:13:15Z")

</div>

@avehtari

I think there is a small incorrectness in the documentation:

### Usage

```no-highlight
extract_list_of_variable_arrays(x, variables = NULL, ...)

```

The parameter is _variable,_ getting an error message:

> ```no-highlight
> > extr2<-extract_variable_array(fit,variables=c("beta"))
> 
> ```
> 
> Error in extract\_variable\_array.default(fit, variables = c(“beta”)) :  
> argument “variable” is missing, with no default

Further, trying to extract all parameters the following error occurs:

> ```no-highlight
> extr2<-extract_variable_array(fit,variable=NULL)
> 
> Error: Cannot coerce ‘variable’ to a single character value.
> 
> ```

> `extr2<-extract_variable_array(fit$draws())`

results in the same message.

\> sessionInfo()  
R version 4.5.2 (2025-10-31)  
Platform: x86\_64-pc-linux-gnu  
Running under: Manjaro Linux

Matrix products: default  
BLAS/LAPACK: /usr/lib/libopenblas.so.0.3; LAPACK version 3.12.0

locale:  
[1] LC\_CTYPE=en\_US.UTF-8 LC\_NUMERIC=C LC\_TIME=de\_DE.UTF-8 LC\_COLLATE=en\_US.UTF-8 LC\_MONETARY=de\_DE.UTF-8  
[6] LC\_MESSAGES=en\_US.UTF-8 LC\_PAPER=de\_DE.UTF-8 LC\_NAME=C LC\_ADDRESS=C LC\_TELEPHONE=C  
[11] LC\_MEASUREMENT=de\_DE.UTF-8 LC\_IDENTIFICATION=C

time zone: Asia/Bangkok  
tzcode source: system (glibc)

attached base packages:  
[1] stats graphics grDevices utils datasets methods base

other attached packages:  
[1] posterior\_1.6.1.9000

loaded via a namespace (and not attached):  
[1] tensorA\_0.36.2.1 generics\_0.1.4 lattice\_0.22-7 magrittr\_2.0.4 ROracle\_1.4-1 evaluate\_1.0.3  
[7] grid\_4.5.2 RColorBrewer\_1.1-3 pkgload\_1.4.0 Matrix\_1.7-4 jsonlite\_2.0.0 processx\_3.8.6  
[13] pkgbuild\_1.4.7 backports\_1.5.0 DBI\_1.2.3 ps\_1.9.1 gridExtra\_2.3 mgcv\_1.9-3  
[19] QuickJSR\_1.7.0 scales\_1.4.0 codetools\_0.2-20 abind\_1.4-8 cli\_3.6.5 rlang\_1.1.7  
[25] cmdstanr\_0.9.0 splines\_4.5.2 remotes\_2.5.0 StanHeaders\_2.36.0.9000 tools\_4.5.2 rstan\_2.36.0.9000  
[31] inline\_0.3.21 parallel\_4.5.2 checkmate\_2.3.3 dplyr\_1.1.4 ggplot2\_4.0.1 curl\_6.2.2  
[37] vctrs\_0.7.1 R6\_2.6.1 matrixStats\_1.5.0 stats4\_4.5.2 lifecycle\_1.0.5 callr\_3.7.6  
[43] desc\_1.4.3 pkgconfig\_2.0.3 RcppParallel\_5.1.10 pillar\_1.11.1 gtable\_0.3.6 loo\_2.8.0  
[49] glue\_1.8.0 Rcpp\_1.1.0 xfun\_0.54 tibble\_3.3.1 tidyselect\_1.2.1 rstudioapi\_0.17.1  
[55] knitr\_1.50 farver\_2.1.2 nlme\_3.1-168 compiler\_4.5.2 S7\_0.2.1 distributional\_0.6.0

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [January 25, 2026, 2:44pm UTC](https://discourse.mc-stan.org/t/new-posterior-extract-list-of-variable-arrays/40838/4 "2026-01-25T14:44:43Z")

</div>

> [@andre.pfeuffer](#):
>
> I think there is a small incorrectness in the documentation:

The documentation is correct. For `extract_list_of_variable_arrays()` the argument is `variables` and for `extract_variable_array()` the argument is `variable`. In one way this makes sense as the first one is usually used for several variables and the second one can be used only for one variable. However, for example, `subset_draws()` uses `variable` also for multiple variables, and it would be logical to change the documentation to say `variable`. Due to how R arguments behave, the current version works with both `variable` and `variables`.

> [@andre.pfeuffer](#):
>
> Further, trying to extract all parameters the following error occurs:
> 
> > ```no-highlight
> > extr2<-extract_variable_array(fit,variable=NULL)
> > 
> > ```

Yes, because you are trying to use `extract_variable_array()` instead of `extract_list_of_variable_arrays()`

> [@andre.pfeuffer](#):
>
> > `extr2<-extract_variable_array(fit$draws())`
> 
> results in the same message.

The same reason.
