fix: as_adjacency_matrix(attr = NULL) is unweighted again - #2842
Merged
Conversation
`attr` and `weights` spell "unweighted" differently. `attr = NULL` was the documented way to ask for a plain 0/1 matrix -- "If `NULL` a traditional adjacency matrix is returned" -- while `weights = NULL` means the opposite: pick up the `weight` edge attribute if the graph has one. The deprecation shim forwarded `attr` to `weights` unchanged, so every call that spelled out `attr = NULL` started returning a weighted matrix, silently and without a warning. The graph having a `weight` attribute is exactly the case where a caller bothers to ask for an unweighted matrix, so the inversion hits precisely the calls that meant it. Translate `NULL` to `weights = NA` instead, and say so in the deprecation warning: following the bare "use `weights` instead" advice literally would reintroduce the same inversion in user code. Both callers of `resolve_edge_weights()` are affected, `as_adjacency_matrix()` and `as_biadjacency_matrix()`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D1xpHRV7yVfgtJg4vp9P7z
The detail line about `weights = NA` only fires for `attr = NULL`, so snapshotting both spellings pins the difference rather than asserting a substring of one of them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D1xpHRV7yVfgtJg4vp9P7z
Contributor
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 0fa7f52 is merged into main:
|
This was referenced Aug 16, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
attrandweightsspell "unweighted" differently, and the deprecation shim forwards one to the other unchanged.attr = NULLwas the documented way to ask for a plain 0/1 matrix. CRAN 2.3.3's?as_adjacency_matrixsays: "attr: EitherNULLor a character string ... IfNULLa traditional adjacency matrix is returned."weights = NULLmeans the opposite: use theweightedge attribute if the graph has one.resolve_edge_weights()didweights <- attr, so every call that spelled outattr = NULLstarted returning a weighted matrix — silently, with no warning beyond the generic "useweightsinstead". A graph having aweightattribute is exactly the case where a caller bothers to ask for an unweighted matrix, so the inversion hits precisely the calls that meant it.lifecycle::is_present(NULL)isTRUE— only thedeprecated()sentinel counts as absent — so the branch really does see an explicitattr = NULLand has to translate it.What changed
attr = NULLnow maps toweights = NA(the new vocabulary for "explicitly unweighted"). A character attribute name is still forwarded unchanged.NULLcase:`attr = NULL` becomes `weights = NA`, not `weights = NULL`.Following the bare advice literally would reintroduce the same inversion in user code.@param attrdocuments the translation instead of claiming the value is always "a character edge attribute name".resolve_edge_weights()—as_adjacency_matrix()andas_biadjacency_matrix()— plus one for the warning text.Reproducer
CRAN 2.3.3 and this branch return a 0/1 matrix;
mainreturns the 0.5/0.7 one.Where this came from
Found while triaging the reverse-dependency failures in #2646.
bnstructcallsas_adjacency_matrix(ig.mst, type = "both", attr = NULL)inbuildJunctionTree-methods.R, on a minimum spanning tree that carries weights — the whole point of the call is to get the topology without them. Introduced by a6ace15 (#2677).What this does not fix
The
attr = NULLspelling is unambiguously a bug: the shim inverts an explicit request. The default is a separate, deliberate-looking question that this PR leaves alone.as_adjacency_matrix(g)with no weight argument at all also changed meaning —weights = NULLpicks upweight, whereattr's defaultNULLdid not. That is the item #2646 raises forsfclust, and it is also what breaksMetaNet:within_module_deg_z_score()andpart_coeff()callas_adj(g, sparse = FALSE)in theirweighted = FALSEbranch andas_adj(g, sparse = FALSE, attr = "weight")in the other, so the unweighted branch now returns the weighted matrix and the Zi/Pi values land outside every role band.Whether the new default is the intended 3.0.0 behaviour is a maintainer call — it is the same shape as the
modularity()item in #2646, and it needs a NEWS entry either way. Flagging it here rather than changing it.🤖 Generated with Claude Code
https://claude.ai/code/session_01D1xpHRV7yVfgtJg4vp9P7z