Skip to content

Some stats fail when the filter selects no data #370

@arcresu

Description

@arcresu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions