feat: error when adding named vertices to non-empty unnamed graphs#2452
Conversation
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
- Changed from cli_warn to cli_abort for non-empty unnamed graphs - Allow adding named vertices to graphs with no edges (empty graphs) - Added snapshot tests for error messages - Removed suppressWarnings from tests that should now work Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Changed to abort instead of warn in commit 8723eee. The implementation now:
The key insight is checking |
- Changed check from ecount(e1) > 0 to vcount(e1) > 0 - Empty graphs are now correctly defined as having 0 vertices, not 0 edges - Updated tests to use make_empty_graph() instead of make_empty_graph(1) - Added tests for make_empty_graph(1) to verify it now errors correctly Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Corrected in commit a4aa43d. Changed the check from |
Resolve the tests/testthat/test-operators.R conflict by keeping all three assertions: this branch's two named-vertices error tests plus main's full-call snapshot. Under this branch's behavior main's case now errors with the named-vertices message (it fires before the attribute recycling check); the operators snapshot records that. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016M32izVHZPfxAqemAe4BrX
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 533b865 is merged into main:
|
Adding named vertices to unnamed graphs creates confusing output where existing vertices have
NAnames and edges display asNA--NA.Changes
+.igraphwhen:vertex()/vertices()with unnamed arguments (interpreted as names) on non-empty unnamed graphs (graphs with vertices)g + c("a", "b")) on non-empty unnamed graphsmake_empty_graph()) is allowed, enabling graph construction from scratchtests/testthat/_snaps/operators.mdThe implementation checks
vcount(e1) > 0to determine if a graph is non-empty. Empty graphs are defined as having zero vertices, consistent with standard graph theory terminology.Example
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.