Skip to content

Orbweaver is an R packages that optimizes the processing of graph data structures.

License

Notifications You must be signed in to change notification settings

andyquinterom/orbweaver

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OrbWeaver

A fast R library for working with Nodes in a graph. This library modifies graphs in place, similar to how data.table modifies data.frames in place. This allows for fast and memory efficient graph operations.

Features

  • Acyclic directed graph
    • Get root nodes
    • Get leaf nodes
    • Get parents of a node
    • Get children of a node
    • Get least common ancestor/parents in a set of nodes
    • Convert to a list (for use in libraries like shinyTree).
    • Create from a data.frame / tibble / derivative

Usage

Create an Acyclic Graph manually

In this example we will build the graph manually.

library(orbweaver)

tree <- new_graph(type = "acyclic") |>
  # Node A has children B and C
  add_child("A", "B") |>
  add_child("A", "C") |>
  # Node B has children D and E
  add_child("B", "D") |>
  add_child("B", "E") |>
  # Node C has child F
  add_child("C", "F")

tree |>
  find_roots()
# [1] "A"

tree |>
  find_leaves("A")
# [1] "F" "E" "D"

tree |>
  find_least_common_parents(c("B", "D", "E"))
# [1] "B"

Create an Acyclic Graph from a data.frame / derivative

library(orbweaver)

example <- data.frame(
  parent = c("A", "A", "B", "B", "C"),
  child = c("B", "C", "D", "E", "F")
)

tree <- example |>
  as_graph(type = "acyclic")

tree |>
  find_roots()
# [1] "A"

tree |>
  find_leaves("A")
# [1] "F" "E" "D"

tree |>
  find_least_common_parents(c("B", "D", "E"))
# [1] "B"

Convert to a list

library(orbweaver)

tree <- new_graph(type = "acyclic") |>
  # Node A has children B and C
  add_child("A", "B") |>
  add_child("A", "C") |>
  # Node B has children D and E
  add_child("B", "D") |>
  add_child("B", "E") |>
  # Node C has child F
  add_child("C", "F")

tree |>
  as.list()
# $A
# $A$C
# $A$C$F
# [1] ""
# 
# 
# $A$B
# $A$B$D
# [1] ""
# 
# $A$B$E
# [1] ""

Installation

Rust Toolchain

Before installing this package, you will need to install the Rust toolchain. If you are on Mac or Linux, you can do this by running the following command in your terminal:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Windows

If you are on Windows, you can download the installer from here.

In order to compile this package manually, you will need the GNU ABI used by the GCC toolchain. This is not the default on Windows, so you will need to install the toolchain manually. You can do this by running the following command in your terminal:

rustup toolchain install stable-gnu

If you are on Windows you may need to install Rtools as well. You can download the installer from here.

R Package

Once you have the Rust toolchain installed, you can install this package from Git using whatever method you prefer.

With remotes:

remotes::install_github("ixpantia/orbweaver")

With devtools:

devtools::install_github("ixpantia/orbweaver")

With renv:

renv::install("ixpantia/orbweaver")

With pak:

pak::pak("ixpantia/orbweaver")

About

Orbweaver is an R packages that optimizes the processing of graph data structures.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 49.3%
  • R 48.9%
  • C 1.8%