-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
should remove_variables be exported? #333
Comments
I think we can export the generic and thus the methods actually. However, then we would have to add all kinds of validity checks, which we currently don't have in place there. I like the idea of adding an BTW: the fact that the remove_variables methods are exported just ensures that they are registered as S3 methods to the generic. They won't actually be exported this way. |
I think an subset_draws.draws_array <- function(x, variable = NULL, iteration = NULL,
chain = NULL, draw = NULL, regex = FALSE,
unique = TRUE, exclude = FALSE, ...) {
if (all_null(variable, iteration, chain, draw)) {
return(x)
}
x <- repair_draws(x)
variable <- check_existing_variables(variable, x, regex = regex)
iteration <- check_iteration_ids(iteration, x, unique = unique)
chain <- check_chain_ids(chain, x, unique = unique)
draw <- check_draw_ids(draw, x, unique = unique)
########## code for exclude option
if (exclude) {
if (!is.null(variable)) {
variable <- setdiff(variables(x), variable)
}
if (!is.null(iteration)) {
iteration <- setdiff(iteration_ids(x), iteration)
}
if (!is.null(chain)) {
chain <- setdiff(chain_ids(x), chain)
}
if (!is.null(draw)) {
draw <- setdiff(draw_ids(x), draw)
}
}
#############
x <- prepare_subsetting(x, iteration, chain, draw)
if (!is.null(draw)) {
iteration <- draw
}
x <- .subset_draws(x, iteration, chain, variable, reserved = TRUE)
if (!is.null(chain) || !is.null(iteration)) {
x <- repair_draws(x, order = FALSE)
}
x
} |
Yes, that looks sensible to me. Thank you! |
Closed by #336 |
I was recently looking for a way to remove unwanted variables from a draws object, and I found that there is a
remove_variables
function (mentioned by in #331) but it does not seem to be exported. Is this intentional?Here, the generic is not exported, but the individual methods appear to be:
https://github.com/stan-dev/posterior/blob/1210f4a42eeb6b942572097d60a8cc2fb8540adf/R/remove_variables.R#L1C1-L14C2
Perhaps another option would be to add an
exclude
parameter insubset_draws
(e.g.subset_draws(example_draws(), variable = "theta", exclude = TRUE)
would remove all theta variables)The text was updated successfully, but these errors were encountered: