edgeWeights              package:graph              R Documentation

_R_e_t_r_i_e_v_e _t_h_e _e_d_g_e _w_e_i_g_h_t_s _o_f _a _g_r_a_p_h

_D_e_s_c_r_i_p_t_i_o_n:

     A generic function that returns the edge weights of a graph.  If
     'index' is specified, only the weights for the edges from the
     specified nodes are returned.  The user can control which edge
     attribute is interpreted as the weight, see the Details section.

_U_s_a_g_e:

     edgeWeights(object, index, ..., attr = "weight", default = 1, type.checker = is.numeric)

_A_r_g_u_m_e_n_t_s:

  object: A graph, any object that inherits from the 'graph' class.

   index: If supplied, a character or numeric vector of node names or
          indices.

     ...: Unused.

    attr: The name of the edge attribute to use as a weight.  You can
          view the list of defined edge attributes and their default
          values using 'edgeDataDefaults'.  The default attribute name
          is '"weight"', see the Details section.

 default: The value to use if 'object' has no edge attribute named by
          the value of 'attr'.  The default is the value 1 (double).

type.checker: A function that will be used to check that the edge
          weights are of the correct type.  This function should return
          TRUE if the input vector is of the right type and FALSE
          otherwise. The default is to check for numeric edge weights
          using 'is.numeric'.  If no type checking is desired, specify
          'NULL'.

_D_e_t_a_i_l_s:

     If 'index' is suppled, then edge weights from these nodes to all
     adjacent nodes are returned. If 'index' is not supplied, then the
     edge weights for all nodes are returned.  The value for nodes
     without any outgoing edges will be a zero-length vector of the
     appropriate mode.

     The 'edgeWeights' method is a convenience wrapper around
     'edgeData', the general-purpose way to access edge attribute
     information for a 'graph' instance.  In general, edge attributes
     can be arbitary R objects.  However, for 'edgeWeights' to make
     sense, the values must be vectors of length not more than one.

     By default, 'edgeWeights' looks for an edge attribute with name
     '"weight"' and, if found, uses these values to construct the edge
     weight list.  You can make use of attributes stored under a
     different name by providing a value for the 'attr' argument.  For
     example, if 'object' is a graph instance with an edge attribute
     named '"WTS"', then the call 'edgeWeights(object, attr="WTS")'
     will attempt to use those values.

     The function specified by 'type.checker' will be given a vector of
     edge weights; if the return value is not 'TRUE', then an error
     will be signaled indicating that the edge weights in the graph are
     not of the expected type.  Type checking is skipped if
     'type.checker' is 'NULL'.

     If the graph instance does not have an edge attribute with name
     given by the value of the 'attr' argument, 'default' will be used
     as the weight for all edges.  Note that if there is an attribute
     named by 'attr', then its default value will be used for edges not
     specifically customized.  See 'edgeData' and 'edgeDataDefaults'
     for more information.

     Because of their position after the '...', no partial matching is
     performed for the arguments 'attr', 'default', and 'type.checker'.

_V_a_l_u_e:

     A named list of named edge weight vectors. The names on the list
     are the names of the nodes specified by 'index', or all nodes if
     'index' was not provided.  The names on the weight vectors are
     node names to identify the edge to which the weight belongs.

_A_u_t_h_o_r(_s):

     R. Gentleman and S. Falcon

_S_e_e _A_l_s_o:

     'nodes' 'edges' 'edgeData' 'edgeDataDefaults' 'is.numeric'
     'is.integer' 'is.character'

_E_x_a_m_p_l_e_s:

       V <- LETTERS[1:4]
       edL2 <- vector("list", length=4)
       names(edL2) <- V
       for(i in 1:4)
         edL2[[i]] <- list(edges=c(2,1,2,1)[i], weights=sqrt(i))
       gR2 <- new("graphNEL", nodes=V, edgeL=edL2, edgemode="directed")
       edgeWeights(gR2, "C")
       edgeWeights(gR2)
       edgeWeights(gR2, attr="foo", default=5)
       edgeData(gR2, attr="weight")
       edgeData(gR2, from="C", attr="weight")

