Open
Description
When manually specifying variable names, I am able to gather_draws
successfully, but, if I specify the same columns via a regular expression, I receive an error:
library(tidybayes)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(tidyr)
my_tidy_draws <-
expand_grid(.chain = 1:2, .iteration = 1:5) |>
mutate(.draw = tidybayes:::draw_from_chain_and_iteration_(.chain, .iteration)) |>
mutate(`aa[1]` = rnorm(n()), `aa[2]` = rnorm(n()), `ab[1]` = rnorm(n())) |>
tidy_draws()
my_tidy_draws |> gather_draws(aa[i], ab[i])
#> # A tibble: 30 × 6
#> # Groups: i, .variable [3]
#> i .chain .iteration .draw .variable .value
#> <int> <int> <int> <int> <chr> <dbl>
#> 1 1 1 1 1 aa 0.0500
#> 2 1 1 2 2 aa -0.187
#> 3 1 1 3 3 aa 1.35
#> 4 1 1 4 4 aa 0.637
#> 5 1 1 5 5 aa 0.856
#> 6 1 2 1 6 aa -0.0731
#> 7 1 2 2 7 aa -1.37
#> 8 1 2 3 8 aa 1.49
#> 9 1 2 4 9 aa -0.765
#> 10 1 2 5 10 aa -1.39
#> # ℹ 20 more rows
my_tidy_draws |> gather_draws(`a.*`[i], regex = T)
#> Error in `unnest_legacy()`:
#> ! All nested columns must have the same number of elements.
Created on 2025-01-07 with reprex v2.1.1
Metadata
Metadata
Assignees
Labels
No labels