igraph / rigraph

igraph R package
https://r.igraph.org
549 stars 200 forks source link

layout_as_tree does not check for empty graph. #558

Closed clpippel closed 2 years ago

clpippel commented 2 years ago

Describe the bug layout_as_tree does not check for empty graph.

To reproduce make_empty_graph() |> plot(layout=layout_as_tree)

produces warning:

Warning message:
In max(res[, 2]) : no non-missing arguments to max; returning -Inf

If you are confident that the issue is not in the R interface but in the C core of igraph, please add it to the main igraph repo instead.

If you are unsure, feel free to add your issue here - we will transfer it to the main igraph repo if the root cause is in the C core of igraph.

Version information [1] igraph_1.3.4

clpippel commented 2 years ago

The functions below also produce warnings:

g <- make_empty_graph()

g |> plot(layout=component_wise)
g |> plot(layout=layout_as_bipartite)
g |> plot(layout=layout_as_star)
g |> plot(layout=layout_with_gem)
g |> plot(layout=layout_with_kk)
g |> plot(layout=layout_with_lgl)
g |> plot(layout=layout_with_mds)
g |> plot(layout=layout_with_sugiyama)
g |> plot(layout=layout_)
g |> plot(layout=merge_coords)
g |> plot(layout=norm_coords)
g |> plot(layout=normalize)
ntamas commented 2 years ago

I've updated your comment above to remove redundant (duplicate) entries. As for the rest:

ntamas commented 2 years ago

3bd98f43 fixes layout_as_star(), updates the C core to fix layout_with_lgl() and layout_with_mds(), and adds test to validate that these functions print no warnings for a null graph.