Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
14 changes: 14 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ideal either, but I know it is sometimes i) missing, or ii) defined by instance_key of the table - maybe we can check for instance_key, and otherwise something like setdiff(names(s), c("radius", "geometry")? At least a little more robust, until we learn better...

s <- s[keep, , drop = FALSE]
shapes(x)[[i]] <- s
}
return(x)
}
Loading