diff --git a/R/methods.R b/R/methods.R index 3b0832b..6522f75 100644 --- a/R/methods.R +++ b/R/methods.R @@ -272,6 +272,8 @@ f <- \(.) setReplaceMethod(., y <- attr(x, paste0(., "s")) y[[i]] <- value attr(x, paste0(., "s")) <- y + if (. == "table") + x <- .sync_shapes_on_drop(x) return(x) }) for (. in one) eval(f(.), parent.env(environment())) diff --git a/R/utils.R b/R/utils.R index b3de2fb..cf84ffe 100644 --- a/R/utils.R +++ b/R/utils.R @@ -72,3 +72,17 @@ tables(x) <- ts return(x) } + +.sync_shapes_on_drop <- \(x) { + if (!length(shapes(x))) return(x) + all_nms <- instances(table(x)) + for (i in seq_along(shapes(x))) { + s <- shapes(x)[[i]] + # check which cells still exist + # FIXME: I kind of doubt this always has this name. Do we have an accessor for this??? + keep <- s[["__index_level_0__"]] %in% all_nms + s <- s[keep, , drop = FALSE] + shapes(x)[[i]] <- s + } + return(x) +} \ No newline at end of file