Package 'forestry'

Title: Reshape Data Tree
Description: 'forestry' a series of utility functions to help with reshaping hierarchy of data tree, and reform the structure of data tree.
Authors: Jiena McLellan [aut, cre], Michael Condouris [ctb], Sai Im [ctb]
Maintainer: Jiena McLellan <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2025-02-20 03:29:16 UTC
Source: https://github.com/jienagu/forestry

Help Index


Add children node

Description

Add children node

Usage

add_child(main_tree, x, assign_node)

Arguments

main_tree

the parent tree to be appended with children node

x

xth child

assign_node

appended node as child

Value

reshaped tree with children assigned


assign attributes to node; work with fix_items function

Description

assign attributes to node; work with fix_items function

Usage

assign_attr(node_from, node_to)

Arguments

node_from

assigned attributes from

node_to

assigned attributes to

Value

a node assigned attributes


Sort chidren nodes with certain order

Description

Sort chidren nodes with certain order

Usage

children_sort(input_node, input_order, mismatch_last = T)

Arguments

input_node

input node

input_order

children node order

mismatch_last

TRUE: mismatched children nodes are at the bottom; FALSE: mismatched nodes are at the top

Value

tree with children nodes sorted with certian order


create a tree with assigned name, children and fields

Description

create a tree with assigned name, children and fields

Usage

create_nodes(tree_name, add_children_count, ...)

Arguments

tree_name

assign name of tree

add_children_count

assign number of chidren to this tree

...

parameters that will be passed as fields of this tree

Value

a tree with assigned name, children and fields

Examples

create_nodes(tree_name = "tree1", add_children_count = 3, class = c("A", "B", "C"))

create tree appended with each element of input list as a child

Description

create tree appended with each element of input list as a child

Usage

create_tree(input_list, node_name)

Arguments

input_list

input list to be made for a tree

node_name

name of the tree

Value

a tree with each item of the list as each child


cumulative calculation

Description

cumulative calculation

Usage

cumsum_across_level(input_node, attri_name, level_num)

Arguments

input_node

tree

attri_name

name of this cummulative count field

level_num

calculate cummulative value cross the level

Value

tree with cummulative count


calculate cumsum for input level

Description

calculate cumsum for input level

Usage

cumsum_by_level(input_tree, level_num, attri_name)

Arguments

input_tree

input tree

level_num

level of tree for cumsum

attri_name

name of this cummulative count field

Value

tree with calculated cumsum for input level


Anonymized sample exercise data

Description

Anonymized sample exercise data

Usage

data(exercise_df)

Format

a data frame ready to convert to a tree

Author(s)

Jiena Gu McLellan, 2020-05-26

Examples

data(exercise_df)

fill missing value of a field across a level with 0

Description

fill missing value of a field across a level with 0

Usage

fill_NA_level(input_node, field_name, by_level, fill_with = 0)

Arguments

input_node

input node

field_name

field for this operation

by_level

across this level

fill_with

fill missing value with this value

Value

node with NA filled for the input field at input level


assign certain children nodes and fill NA for empty fields

Description

assign certain children nodes and fill NA for empty fields

Usage

fix_items(fix_vector, input_node)

Arguments

fix_vector

children node names to be assigned

input_node

the node to be exapnded with children's names

Value

a node expanded with certain children nodes


numericalize children numeric name to convert JSON object to JSON array

Description

numericalize children numeric name to convert JSON object to JSON array

Usage

fixnames(x)

Arguments

x

input

Value

unname numeric names list


numericalize children numeric name to convert JSON object to JSON array

Description

numericalize children numeric name to convert JSON object to JSON array

Usage

pre_get_array(x)

Arguments

x

input list

Value

unname numeric names list which is prepared to convert to JSON array


Anonymized sample data

Description

Anonymized sample data

Usage

data(test_df)

Format

a data frame ready to convert to a tree

Author(s)

Jiena Gu McLellan, 2020-05-26

Examples

data(test_df)