igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Non-atomic attributes?


From: Gábor Csárdi
Subject: Re: [igraph] Non-atomic attributes?
Date: Sun, 1 Feb 2009 02:06:48 +0100

It is not obvious, and it is especially poorly documented. The trick
is to assign lists, even if you do the assignment for a single
vertex/edge only, in this case a list with one element:

g <- graph.ring(4)
V(g)[0]$complex <- list(1:4)

> V(g)[0]$complex <- list(1:4)
> V(g)$complex
[[1]]
[1] 1 2 3 4

[[2]]
[1] 1 2 3 4

[[3]]
[1] 1 2 3 4

[[4]]
[1] 1 2 3 4

> V(g)$complex <- list(5:6, data.frame())
> V(g)$complex
[[1]]
[1] 5 6

[[2]]
data frame with 0 columns and 0 rows

[[3]]
[1] 5 6

[[4]]
data frame with 0 columns and 0 rows

Version 0.5.1 handles 'recycling' in a bit strange way, so when you
initially assign the attribute to a single vertex only, other vertices
with a higher vertex id get the same value. This is a bug and it has
been corrected already in the coming version. A workaround is to
assign a value to all vertices/edges in the first step, or just
afterwards.

Note that complex attributes are not written to GML or GraphML files
currently. Or course they are kept if you use save and load.

Hope this helps,
G.

On Sat, Jan 31, 2009 at 11:24 PM, Dan Auerbach <address@hidden> wrote:
> Apologies if I've missed something obvious, but a search through the list
> archives and the help and documentation on the igraph homepage hasn't helped
> so far...
> Using 2.8.1 and 0.5.1,
> In the R-igraph help it is stated:
> "In recent igraph versions, arbitrary R objects can be assigned as graph,
> vertex or edge attributes."
> I took this to mean that, for example, a vertex attribute could consist of
> vectors, matrices, lists, etc., but I can't seem to assign a vector as a
> vertex attribute, e.g.
>>g=graph.lattice(c(3,1))
>>V(g)[1]$test = c(1,2,3,4)
> Warning message:
> In graph[[9]][[3]][[name]][index + 1] <- value :
>   number of items to replace is not a multiple of replacement length
>> V(g)$test
> [1] NA  1 NA
> I've tried assigning pre-declared objects, e.g.
>>a= c(1,2,3,4..)
>>V(g)[1]$test = a
> and assignments to all vertices first (rather to a than a single vertex
> index),
> and I've tried to set the dim() on attributes,
> but so far I can't assign anything other than atomics.
> I can get around this with arrays that are referenced by vertex id, but it
> would be nice to integrate the info into the single graph data structure.
> Am I misinterpreting the package capabilities or making an obvious error
> (like somehow declaring the attribute class?)
> Thanks
> Dan Auerbach
>
> 970-491-2414
> Graduate Degree Program in Ecology
> Dept. of Biology
> Colorado State Univ.
> Fort Collins, CO 80523-1878
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>



-- 
Gabor Csardi <address@hidden>     UNIL DGM




reply via email to

[Prev in Thread] Current Thread [Next in Thread]