Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[<-.network error with missing edge #75

Open
chad-klumb opened this issue Apr 20, 2022 · 2 comments
Open

[<-.network error with missing edge #75

chad-klumb opened this issue Apr 20, 2022 · 2 comments

Comments

@chad-klumb
Copy link
Contributor

chad-klumb commented Apr 20, 2022

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")
@krivit
Copy link
Member

krivit commented May 21, 2022

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?

@CarterButts
Copy link
Contributor

Whether an edge is missing shouldn't have any bearing on what attributes it carries. Bear in mind here that, to network, an "edge" is a data object saying that there's some kind of information regarding a set of vertices that needs to be stored. The na attribute is a standard way of recording that the adjacency of that set is unknown, but there's no rule that says that you can't store other information on that set. How that information gets reported back will vary, of course: for instance, as.matrix(nw,attrname="attr2") will report an NA for the missing edge, as it should. But you should be able to store the information without it getting garbled. So this seems to be a bug (looks like it arises from an incorrect assumption that is.adjacent won't return NA ). Too late for the 1.19.0 release, but should be fixed for the next one....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants