get_parents: Get all parrents of a node

Description Usage Arguments Details Value Examples

View source: R/get_parents.R

Description

get_parents() returns all parents, grandparents, grand grandparents, etc. of your input node.

Usage

1
get_parents(graph_dt, get_node, return_nodes = TRUE)

Arguments

graph_dt

data.table; A data.table with a "from" and a "to" column. See details for more.

get_node

character; The name of the node(s) who's parents you are looking for

return_nodes

logical; If TRUE (default) the function will return both the inputted graph_dt along with a nodes data.table. See return for more.

Details

The function takes as its input a data.table (graph_dt) with at least two columns called "from" and "to" and potentially many more.

Value

It will return the inputted graph_dt data.table but only with parents included.

If return_nodes is TRUE it will also retun a data.table with node ids including a column called level showing you how many generations there are between the diffent nodes and the inputted node (get_node).

When return_nodes is TRUE it returns both data.tables in a list called nodes and edges.

Examples

1
2
3
4
5
6
7
8
my_network <- data.table::data.table(
  from = c("A", "A", "B", "C", "X", "Y", "D"),
  to = c("B", "C", "D", "E", "Y", "Z", "E")
)

my_parents <- get_parents(my_network, "B")

my_parents <- get_parents(my_network, "E", return_nodes = FALSE)

emillykkejensen/familyR documentation built on May 4, 2019, 3:12 a.m.