subset_draws duplicates variables if `variables` argument contains `NA`
When subsetting by variable, if NA is included in the variable argument along with other strings, the matched variables are duplicated in the output.
Example:
example_draws() |>
subset_draws(variable = c("mu", NA)) |>
variables()
#> [1] "mu" "mu"
Looks like an issue with the check_existing_variables() helper:
(check_existing_variables(c("mu", NA), example_draws()))
## [1] "mu" "mu"
Great, probably not too complex of a fix then. But I also wonder if it ever makes sense to allow NA in variable. Maybe there should be an input check disallowing this?
Yeah good point. The two options to my mind are:
- throw an error in
check_existing_variables()if any elements ofvariableareNA. - something consistent with how variable selection works in base R subsetting, like returning a variable that is
ndraws(x)ofNAfor that entry in the output.
I think I'd be fine with throwing an error since it probably isn't that useful to do variable subsetting by names with NAs, and throwing an error would be simpler. Then if a use case arises for this later we could consider implementing it.
@mjskay I think your first suggestion (throwing an error if names includes NA) would make the most sense at this stage
I agree. @n-kall would you mind making a small PR to fix this issue?
Sure, can do