stan-dev / posterior

The posterior R package
https://mc-stan.org/posterior/
Other
167 stars 23 forks source link

subset_draws duplicates variables if `variables` argument contains `NA` #365

Open n-kall opened 4 months ago

n-kall commented 4 months ago

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"
mjskay commented 4 months ago

Looks like an issue with the check_existing_variables() helper:

(check_existing_variables(c("mu", NA), example_draws()))
## [1] "mu" "mu"
n-kall commented 4 months ago

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?

mjskay commented 4 months ago

Yeah good point. The two options to my mind are:

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.

n-kall commented 3 months ago

@mjskay I think your first suggestion (throwing an error if names includes NA) would make the most sense at this stage