Skip to content
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

Some stats fail when the filter selects no data #370

Open
arcresu opened this issue May 15, 2024 · 0 comments
Open

Some stats fail when the filter selects no data #370

arcresu opened this issue May 15, 2024 · 0 comments

Comments

@arcresu
Copy link
Contributor

arcresu commented May 15, 2024

When a filter aesthetic doesn't leave behind any data, some stats fail, e.g. adapted from the geom_edge_elbow() example:

irisDen <- hclust(dist(iris[1:4], method = 'euclidean'), method = 'ward.D2')

# this is basically the example from the docs, it runs fine:
ggraph(irisDen, 'dendrogram', circular = TRUE) + geom_edge_elbow()

# this errors:
ggraph(irisDen, 'dendrogram', circular = TRUE) + geom_edge_elbow(aes(filter = FALSE))
# Warning message:
# Computation failed in `stat_edge_elbow()`.
# Caused by error in `if (!data$circular[1] && n%%2 == 0) ...`:
# ! missing value where TRUE/FALSE needed

# this makes an empty plot with no errors:
ggraph(irisDen, 'dendrogram', circular = TRUE) +
  geom_edge_elbow(data = function(x) { data <- get_edges()(x); data[FALSE, names(data) != 'filter'] })

I'm guessing this is related to #324 and its fix (945bdf1).

With some print statement debugging, I found that StatEdgeElbow$compute_panel is called with an empty data frame when aes(filter=FALSE), but isn't called at all with the version that filters using data=, presumably because of the way it's invoked in Stat$compute_layer. That means filtering with data= is a workaround.

I imagine the fix would be either to return early in $compute_panel() when there is no data, or assume a default circularity value when there is no data. This would apply to many stats, not just StatEdgeElbow.

arcresu added a commit to cidm-ph/phylepic that referenced this issue May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant