network icon indicating copy to clipboard operation
network copied to clipboard

`[<-.network` error with missing edge

Open chad-klumb opened this issue 2 years ago • 2 comments

The following example shows how %e%<- and [<-.network (with names.eval passed) behave similarly with no missing edges, but the latter errors when an edge is missing.

require(network)
nw <- network.initialize(3, directed = FALSE)
nw[1,2] <- 1
nw[2,3] <- 1
nw %e% "attr1" <- "b"
nw %e% "attr1"
nw[,,names.eval="attr2"] <- "c"
nw %e% "attr2"
nw[2,3] <- NA
nw %e% "attr3" <- "d"
nw %e% "attr3"
nw[,,names.eval="attr4"] <- "e"

the error on the last line being

Error in if (is.adjacent(x, el[k, 1], el[k, 2], na.omit = FALSE)) { : 
  missing value where TRUE/FALSE needed

with traceback

> traceback()
2: `[<-.network`(`*tmp*`, , , names.eval = "attr4", value = "e")
1: `[<-`(`*tmp*`, , , names.eval = "attr4", value = "e")

chad-klumb avatar Apr 20 '22 13:04 chad-klumb

This is easily fixed, but it's a "philosophical" question: if an edge is marked as missing (i.e., has its na attribute set to TRUE), what value should this call assign to it?

In the above case, what should the attribute attr4 of edge (2,3) be assigned?

  1. Nothing.
  2. "e".
  3. NA (NA of type logical).
  4. NA_character_ (NA of the same type as the assigned value).

@CarterButts, what do you think?

krivit avatar May 21 '22 07:05 krivit