Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind_draws() for lists of draws objects #253

Closed
mjskay opened this issue Aug 15, 2022 · 1 comment · Fixed by #259
Closed

bind_draws() for lists of draws objects #253

mjskay opened this issue Aug 15, 2022 · 1 comment · Fixed by #259

Comments

@mjskay
Copy link
Collaborator

mjskay commented Aug 15, 2022

Over the past week or two I have encountered multiple instances when helping some folks with {posterior} where I wished bind_draws() had an implementation for lists. See, for example, this bit of code from here:

betas_dfs = lapply(anes_2012_models, function(m) posterior::as_draws_df(t(m$beta)))
betas_df = do.call(posterior::bind_draws, c(betas_dfs, list(along = "draw")))

Basically, the issue is that if you have a list of draws objects like betas_dfs and want to bind them together along something other than variables (along = "variable" is the default for bind_draws()), you have to make a fairly ugly construction with do.call().

The alternative is to allow arguments to bind_draws() to be draws objects or lists of draws objects (similar to how dplyr::bind_rows() works on data frame or lists of data frames). Then the second line above could just be:

betas_df = posterior::bind_draws(betas_dfs, along = "draw")
@paul-buerkner
Copy link
Collaborator

I like the option of supporting lists of draws objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants