1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/mutate_edge_attrs_ws.R
3\name{mutate_edge_attrs_ws}
4\alias{mutate_edge_attrs_ws}
5\title{Mutate edge attribute values for a selection of edges}
6\usage{
7mutate_edge_attrs_ws(graph, ...)
8}
9\arguments{
10\item{graph}{A graph object of class \code{dgr_graph}.}
11
12\item{...}{Expressions used for the mutation of edge attributes. LHS of each
13expression is either an existing or new edge attribute name. The RHS can
14consist of any valid R code that uses edge attributes as variables.
15Expressions are evaluated in the order provided, so, edge attributes
16created or modified are ready to use in subsequent expressions.}
17}
18\value{
19A graph object of class \code{dgr_graph}.
20}
21\description{
22Within a graph's internal edge data frame (edf), mutate edge attribute values
23only for edges in a selection by using one or more expressions.
24}
25\details{
26This function makes use of an active selection of edges (and the function
27ending with \verb{_ws} hints at this).
28
29Selections of edges can be performed using the following selection
30(\verb{select_*()}) functions: \code{\link[=select_edges]{select_edges()}}, \code{\link[=select_last_edges_created]{select_last_edges_created()}},
31\code{\link[=select_edges_by_edge_id]{select_edges_by_edge_id()}}, or \code{\link[=select_edges_by_node_id]{select_edges_by_node_id()}}.
32
33Selections of edges can also be performed using the following traversal
34(\verb{trav_*()}) functions: \code{\link[=trav_out_edge]{trav_out_edge()}}, \code{\link[=trav_in_edge]{trav_in_edge()}},
35\code{\link[=trav_both_edge]{trav_both_edge()}}, or \code{\link[=trav_reverse_edge]{trav_reverse_edge()}}.
36}
37\examples{
38# Create a graph with 3 edges
39# and then select edge `1`
40graph <-
41  create_graph() \%>\%
42  add_path(n = 4) \%>\%
43  set_edge_attrs(
44    edge_attr = width,
45    values = c(3.4, 2.3, 7.2)) \%>\%
46  select_edges(edges = 1)
47
48# Get the graph's internal edf
49# to show which edge attributes
50# are available
51graph \%>\% get_edge_df()
52
53# Mutate the `width` edge
54# attribute for the edges
55# only in the active selection
56# of edges (edge `1`); here,
57# we divide each value in the
58# selection by 2
59graph <-
60  graph \%>\%
61  mutate_edge_attrs_ws(
62    width = width / 2)
63
64# Get the graph's internal
65# edf to show that the edge
66# attribute `width` had its
67# values changed
68graph \%>\% get_edge_df()
69
70# Create a new edge attribute,
71# called `length`, that is the
72# log of values in `width` plus
73# 2 (and, also, round all values
74# to 2 decimal places)
75graph <-
76  graph \%>\%
77  clear_selection() \%>\%
78  select_edges(edges = 2:3) \%>\%
79  mutate_edge_attrs_ws(
80    length = (log(width) + 2) \%>\%
81               round(2))
82
83# Get the graph's internal edf
84# to show that the edge attribute
85# values had been mutated only
86# for edges `2` and `3` (since
87# edge `1` is excluded, an NA
88# value is applied)
89graph \%>\% get_edge_df()
90
91# Create a new edge attribute
92# called `area`, which is the
93# product of the `width` and
94# `length` attributes
95graph <-
96  graph \%>\%
97  mutate_edge_attrs_ws(
98    area = width * length)
99
100# Get the graph's internal edf
101# to show that the edge attribute
102# values had been multiplied
103# together (with new attr `area`)
104# for nodes `2` and `3`
105graph \%>\% get_edge_df()
106
107# We can invert the selection
108# and mutate edge `1` several
109# times to get an `area` value
110# for that edge
111graph <-
112  graph \%>\%
113  invert_selection() \%>\%
114  mutate_edge_attrs_ws(
115    length = (log(width) + 5) \%>\%
116               round(2),
117    area = width * length)
118
119# Get the graph's internal edf
120# to show that the 2 mutations
121# occurred for edge `1`, yielding
122# non-NA values for its edge
123# attributes without changing
124# those of the other edges
125graph \%>\% get_edge_df()
126
127}
128\seealso{
129Other Edge creation and removal:
130\code{\link{add_edge_clone}()},
131\code{\link{add_edge_df}()},
132\code{\link{add_edges_from_table}()},
133\code{\link{add_edges_w_string}()},
134\code{\link{add_edge}()},
135\code{\link{add_forward_edges_ws}()},
136\code{\link{add_reverse_edges_ws}()},
137\code{\link{copy_edge_attrs}()},
138\code{\link{create_edge_df}()},
139\code{\link{delete_edges_ws}()},
140\code{\link{delete_edge}()},
141\code{\link{delete_loop_edges_ws}()},
142\code{\link{drop_edge_attrs}()},
143\code{\link{edge_data}()},
144\code{\link{join_edge_attrs}()},
145\code{\link{mutate_edge_attrs}()},
146\code{\link{recode_edge_attrs}()},
147\code{\link{rename_edge_attrs}()},
148\code{\link{rescale_edge_attrs}()},
149\code{\link{rev_edge_dir_ws}()},
150\code{\link{rev_edge_dir}()},
151\code{\link{set_edge_attr_to_display}()},
152\code{\link{set_edge_attrs_ws}()},
153\code{\link{set_edge_attrs}()}
154}
155\concept{Edge creation and removal}
156