edge_list: Create an edge list

View source: R/node_edge_list.R

edge_listR Documentation

Create an edge list

Description

An edge list is a data frame in which each row describes a flow from one entity to another. Columns in the edge list data frame are From, To, Value, and Product. The edge list can be created from the U, V, and Y matrices of an energy conversion chain. Edge lists is a typical data format for visualization software.

Usage

edge_list(
  .sutdata = NULL,
  R = "R",
  U = "U",
  V = "V",
  Y = "Y",
  edge_list = "Edge list",
  from = "From",
  to = "To",
  value = "Value",
  product = "Product",
  waste = "Waste",
  rowtypes = "rowtype",
  coltypes = "coltype",
  node_id = "node_id",
  first_node = 0,
  edge_id = "edge_id",
  simplify_edges = TRUE
)

Arguments

.sutdata

Optionally, a data frame containing columns named with the values of the U, V, and Y arguments.

R

a resource matrix or the name of a column in .sutdata containing resource matrices. (Default is "R".)

U

a use matrix or the name of a column in .sutdata containing use matrices. (Default is "U".)

V

a make matrix or the name of a column in .sutdata containing make matrices. (Default is "V".)

Y

a final demand matrix or the name of a column in .sutdata containing final demand matrices. (Default is "Y".)

edge_list

the name of the column in the output data frame containing edge lists. Or the name of the item in the return list if .sutdata is not specified. (Default is "Edge list".)

from

the name of the edge list column containing source nodes. (Default is "From".)

to

the name of the edge list column containing destination nodes. (Default is "To".)

value

the name of the edge list column containing magnitudes of the flows. (Default is "Value".)

product

the name of the edge list column containing the product of the edge list flow. (Default is "Product".)

waste

the name of the waste product and the destination node for wastes. Set NULL to suppress addition of waste edges. (Default is "Waste".)

rowtypes

the name of the rowtypes. (Default is "rowtype".)

coltypes

the name of the rowtypes. (Default is "coltype".)

node_id

the base name of node ID columns. Set NULL to suppress addition of node ID numbers. (Default is "node_id".)

first_node

the first node number. (Default is 0.)

edge_id

the name of the edge ID column. Set NULL to suppress addition of edge ID numbers. (Default is "edge_id".)

simplify_edges

if TRUE, products with only one source will not have a node. The source of the product will be connected directly to its consumers. If FALSE, no simplifications are made. (Default is TRUE.)

Details

Optionally, waste streams can be calculated from the U and V matrices and added to the edge list. Optionally, edges can be simplified when a product has a single source. In that event, the node named after the product is removed, and destinations are connected to the sources.

Value

an edge list or a column of edge lists

Examples

library(matsbyname)
library(tidyr)
sutmats <- UKEnergy2000mats %>%
  spread(key = matrix.name, value = matrix)
# Don't simplify edges and don't include waste edges
el_basic <- edge_list(sutmats, simplify_edges = FALSE)
head(el_basic$`Edge list`[[1]])
tail(el_basic$`Edge list`[[1]])
# Simplify edges and include waste
el <- edge_list(sutmats)
head(el$`Edge list`[[1]])
# Now includes waste edges
tail(el$`Edge list`[[1]])
# Works with single matrices, too.
elmats <- edge_list(R = sutmats$R[[1]], U = sutmats$U[[1]], V = sutmats$V[[1]], Y = sutmats$Y[[1]])
head(elmats[["Edge list"]])
tail(elmats[["Edge list"]])

MatthewHeun/Recca documentation built on Feb. 9, 2024, 6:18 p.m.