Help: Error message "length of NULL cannot be changed"

When trying to generate colors or change the weight of edges when using igraph I’m generating the error “length of NULL cannot be changed.”

Specifically when running these codes:

    colrs <- c("skyblue", "orchid2", "peachpuff")
    V(net)$color <- colrs[V(net)$source]

I get:

Warning message:
In length(vattrs[[name]]) <- vc : length of NULL cannot be changed

When I run the code:

E(net)$width <- E(net)$weight/6

I get the same error. Has anyone gotten similar errors and know what to do with them in this context? Thank you

1 Like

I am unable reproduce your problem. Please post a minimal working example of your problem. Perhaps it would then be possible to identify the problem.

Were you able to identify a solution to this issue?

@bimaben As stated above, in order to help, we need a minimal example that demonstrates the problem. See here for guidance: How to create a Minimal, Reproducible Example - Help Center - Stack Overflow

Try.

net          <- graph_from_literal(A-B, A-C)
colrs        <- c("skyblue", "orchid2", "peachpuff") 
V(net)$color <- colrs[V(net)$source]
V(net)$color <- character(0)
E(net)$width <- E(net)$weight/6
E(net)$width <- numeric(0)

These error messages occur because V(g)$color and E(g)$weight do not exists and dependent expressions are coerced to character(0) and numeric(0) respectively.