\HeaderA{attributes}{Graph, vertex and edge attributes}{attributes}
\aliasA{get.edge.attribute}{attributes}{get.edge.attribute}
\aliasA{get.graph.attribute}{attributes}{get.graph.attribute}
\aliasA{get.vertex.attribute}{attributes}{get.vertex.attribute}
\aliasA{list.edge.attributes}{attributes}{list.edge.attributes}
\aliasA{list.graph.attributes}{attributes}{list.graph.attributes}
\aliasA{list.vertex.attributes}{attributes}{list.vertex.attributes}
\aliasA{remove.edge.attribute}{attributes}{remove.edge.attribute}
\aliasA{remove.graph.attribute}{attributes}{remove.graph.attribute}
\aliasA{remove.vertex.attribute}{attributes}{remove.vertex.attribute}
\aliasA{set.edge.attribute}{attributes}{set.edge.attribute}
\aliasA{set.graph.attribute}{attributes}{set.graph.attribute}
\aliasA{set.vertex.attribute}{attributes}{set.vertex.attribute}
\keyword{graphs}{attributes}
\begin{Description}\relax
Attributes are associated values belonging to a graph,
vertices or edges. These can represent some property, like data
about how the graph was constructed, the color of the vertices when
the graph is plotted, or simply the weights of the edges in a weighted
graph.
\end{Description}
\begin{Usage}
\begin{verbatim}
get.graph.attribute(graph, name)
graph <- set.graph.attribute(graph, attrname, value)
graph <- remove.graph.attribute(graph, attrname)
get.vertex.attribute(graph, name, index=V(graph))
graph <- set.vertex.attribute(graph, attrname, index=V(graph), value)
graph <- remove.vertex.attribute(graph, attrname)
get.edge.attribute(graph, name, index=E(graph))
graph <- set.edge.attribute(graph, attrname, index=E(graph), value)
graph <- remove.edge.attribute(graph, attrname)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{graph}] The graph object to work on. Note that the original graph
is never modified, a new graph object is returned instead; if you don't
assign it to a variable your modifications will be lost! See examples
below.
\item[\code{name}] Character constant, the name of the attribute.
\item[\code{index}] Numeric vector, the ids of the vertices or edges.
It is not recycled, even if \code{value} is longer.
\item[\code{value}] Numeric vector, the new value(s) of the attributes, it
will be recycled if needed.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
There are three types of attributes in igraph: graph, vertex and edge
attributes. Graph attributes are associated with graph, vertex
attributes with vertices and edge attributes with edges.

Examples for graph attributes are the date when the graph data was
collected or other types of memos like the type of the data, or
whether the graph is a simple graph, ie. one without loops and
multiple edges.

Examples of vertex attributes are vertex properties, like the
vertex coordinates for the visualization of the graph, or other
visualization parameters, or meta-data associated with the vertices,
like the gender and the age of the individuals in a friendship
network, the type of the neurons in a graph representing neural
circuitry or even some pre-computed structual properties, like the
betweenness centrality of the vertices.

Examples of edge attributes are data associated with edges: most
commonly edge weights, or visualization parameters.

In recent igraph versions, arbitrary R objects can be assigned as
graph, vertex or edge attributes.

Some igraph functions use the values or graph, vertex and edge
attributes if they are present but this is not done in the current
version very extensively. Expect more in the (near) future.

Graph attributes can be created with the \code{set.graph.attribute}
function, and removed with \code{remove.graph.attribute}. Graph
attributes are queried with \code{get.graph.attribute} and the
assigned graph attributes are listed with
\code{list.graph.attributes}.

There is a simpler notation for using graph attributes: the
\sQuote{\code{\$}} operator. It can be used both to query and set graph
attributes, see an example below.

The functions for vertex attributes are
\code{set.vertex.attribute}, \code{get.vertex.attribute},
\code{remove.vertex.attribute} and \code{list.vertex.attributes} and
for edge attributes they are \code{set.edge.attribute},
\code{get.edge.attribute}, \code{remove.edge.attribute} and
\code{list.edge.attributes}.

There is however a (syntactically) much simpler way to handle vertex
and edge attribute by using vertex and edge selectors, it works like this:
\code{V(g)} selects all vertices in a graph, and \code{V(g)\$name}
queries the \code{name} attribute for all vertices. Similarly is
\code{vs} is a vertex set \code{vs\$name} gives the values of the
\code{name} attribute for the vertices in the vertex set.

This form can also be used to set the values of the attributes, like
the regular R convention:
\begin{alltt}V(g)\$color <- "red"\end{alltt}
It works for vertex subsets as well:
\begin{alltt}V(g)[0:5]\$color <- "green"\end{alltt}

The notation for edges is similar: \code{E(g)} means all edges
\code{E(g)\$weight} is the \code{weight} attribute for all edges, etc.

See also the manual page for \code{iterators} about how to create
various vertex and edge sets.
\end{Details}
\begin{Value}
\code{get.graph.attribute}, \code{get.vertex.attribute} and
\code{get.edge.attribute} return an R object, or a list of R objects
if attributes of more vertices/edges are requested.

\code{set.graph.attribute}, \code{set.vertex.attribute},
\code{set.edge.attribute}, and also \code{remove.graph.attribute},
\code{remove.vertex.attribute} and \code{remove.edge.attribute} return
a new graph object with the updates/removes performed.

\code{list.graph.attributes}, \code{list.vertex.attributes} and
\code{list.edge.attributes} return a character vector, the names of
the attributes present.
\end{Value}
\begin{Author}\relax
Gabor Csardi \email{csardi@rmki.kfki.hu}
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{print.igraph}{print.igraph}} can also print attributes
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
g <- graph.ring(10)
g <- set.graph.attribute(g, "name", "RING")
# It is the same as
g$name <- "RING"
g$name

g <- set.vertex.attribute(g, "color", value=c("red", "green"))
get.vertex.attribute(g, "color")

g <- set.edge.attribute(g, "weight", value=runif(ecount(g)))
get.edge.attribute(g, "weight")

# The following notation is more convenient

g <- graph.star(10)

V(g)$color <- c("red", "green")
V(g)$color

E(g)$weight <- runif(ecount(g))
E(g)$weight

print(g, g=TRUE, v=TRUE, e=TRUE)
\end{ExampleCode}
\end{Examples}

