make_index_ids: Make Index ids

View source: R/make_index_ids.R

make_index_idsR Documentation

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, long_form = FALSE)

## S3 method for class 'data.frame'
make_index_ids(x, long_form = FALSE)

## S3 method for class 'hy'
make_index_ids(x, long_form = FALSE)

Arguments

x

data.frame network compatible with hydroloom_names.

long_form

logical if TRUE, return will be a long-form version of the to_list. This form can be converted to the default list format with format_index_ids.

Value

list containing named elements: to: adjacency matrix lengths: vector indicating the number of connections from each node, and: to_list: a data.frame with an id, indid and a toindid list column. If long_form = TRUE, return will be a long form data.frame with no list column as in to_list. NOTE: the long_form output should be used with caution as indid may not correspond to row number.

Examples


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)

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)


hydroloom documentation built on Sept. 29, 2023, 5:09 p.m.