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

tidy_draws dataframe with whitespace in dimensions #329

Open
damonbayer opened this issue Nov 13, 2024 · 0 comments
Open

tidy_draws dataframe with whitespace in dimensions #329

damonbayer opened this issue Nov 13, 2024 · 0 comments

Comments

@damonbayer
Copy link

damonbayer commented Nov 13, 2024

Is there any way to have a tidy_draws dataframe work correctly with dimensions that have whitespace?

It seems like there could be some workaround using the "tidybayes_constructors" attribute like in recover_types, but that relies on knowing what the dimension will be called, which is not ideal.

Example of things not working as desired:

library(tidyverse)
library(tidybayes)

my_tidy_draws <- 
  expand_grid(.chain = 1:4, .iteration = 1:5) |> 
  mutate(.draw = tidybayes:::draw_from_chain_and_iteration_(.chain, .iteration)) |> 
  mutate(`x[group with a space]` = rnorm(n()),
         `x[another group]` = rnorm(n())) |> 
  tidy_draws()

spread_draws(my_tidy_draws, x[a])
#> Warning: Expected 1 pieces. Additional pieces discarded in 2 rows [1, 2].
#> # A tibble: 40 × 5
#> # Groups:   a [2]
#>    a            x .chain .iteration .draw
#>    <chr>    <dbl>  <int>      <int> <int>
#>  1 another -2.41       1          1     1
#>  2 another -1.16       1          2     2
#>  3 another -1.85       1          3     3
#>  4 another  0.156      1          4     4
#>  5 another -1.50       1          5     5
#>  6 another -0.286      2          1     6
#>  7 another  0.487      2          2     7
#>  8 another  0.169      2          3     8
#>  9 another  0.582      2          4     9
#> 10 another -1.10       2          5    10
#> # ℹ 30 more rows

Created on 2024-11-13 with reprex v2.1.1

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

No branches or pull requests

1 participant