warning in graph_from_adjacency_matrix() example
library("igraph")
#>
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#>
#> decompose, spectrum
#> The following object is masked from 'package:base':
#>
#> union
nzs <- function(x) sort(x[x != 0])
adjm <- matrix(runif(100), 10)
adjm[adjm < 0.5] <- 0
g3 <- graph_from_adjacency_matrix((adjm + t(adjm)) / 2,
weighted = TRUE,
mode = "undirected"
)
g4 <- graph_from_adjacency_matrix(adjm, weighted = TRUE, mode = "max")
all(nzs(pmax(adjm, t(adjm))[upper.tri(adjm)]) == sort(E(g4)$weight))
#> Warning in nzs(pmax(adjm, t(adjm))[upper.tri(adjm)]) == sort(E(g4)$weight):
#> longer object length is not a multiple of shorter object length
#> [1] FALSE
Created on 2024-03-11 with reprex v2.1.0
this happens several times in that same Rd file.
Maelle, Is there a compelling reason why this error would not occur?
I think it'd be better if the example didn't show a warning, now I need to think about how to achieve this.
Note that function d0() in
g9 <- graph_from_adjacency_matrix(adjm, weighted = TRUE, mode = "plus", diag = FALSE)
d0 <- function(x) {
diag(x) <- 0
}
is wrong. It must end with return(x). Otherwise
all(nzs((d0(adjm + t(adjm)))[lower.tri(adjm)]) == sort(E(g9)$weight))
will always return TRUE.
The solution is to add diag=TRUE in upper.tri() and lower.tri() except the one after g9 in the code. This will eliminate the warnings.
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.