Learn R Programming

hydroloom (version 1.1.2)

make_index_ids: Make Index ids

Description

makes index ids for the provided hy object. These can be used for graph traversal algorithms such that the row number and id are equal.

Usage

make_index_ids(x, mode = "to", long_form = NULL)

# S3 method for data.frame make_index_ids(x, mode = "to", long_form = NULL)

# S3 method for hy make_index_ids(x, mode = "to", long_form = NULL)

Value

list containing named elements:

to

adjacency matrix with columns that correspond to unqiue(x$id)

lengths

vector indicating the number of connections from each node

to_list

a data.frame with an id, indid and a toindid list column.

List will have names froms, lengths, and froms_list for mode "from".

NOTE: the long_form output is deprecated and will be removed in a future release.

Arguments

x

data.frame network compatible with hydroloom_names.

mode

character indicating the mode of the graph. Choose from "to", "from", or "both". Default is "to". Se Details for more information.

long_form

logical DEPRECATED

Details

Required attributes: id, toid

mode determines the direction of the graph. If "to", the graph will be directed from the id to the toid. If "from", the graph will be directed from the toid to the id. If "both", the list will contain both a "from" and a "to" element containing each version of the graph.

Examples

Run this code

x <- data.frame(
  id = c(1, 2, 3, 4, 5, 6, 7, 8, 9),
  toid = c(2, 3, 4, 5, 0, 7, 8, 9, 4)
)

make_index_ids(x, mode = "to")

make_index_ids(x, mode = "from")

make_index_ids(x, mode = "both")

x <- hy(sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom")))

x <- add_toids(x, return_dendritic = FALSE)

x <- make_index_ids(x)

names(x)
class(x$to)
class(x$lengths)
class(x$to_list)
is.list(x$to_list$toindid)

Run the code above in your browser using DataLab