Skip to content

Commit

Permalink
chore: Adds additional test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
andyquinterom committed Jun 12, 2024
1 parent d37d749 commit 2dc78f5
Show file tree
Hide file tree
Showing 26 changed files with 479 additions and 155 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: orbweaver
Title: Fast and Efficient Graph Data Structures
Version: 0.6.1
Version: 0.10.1
Authors@R:
c(person(given = "ixpantia, SRL",
role = "cph",
Expand All @@ -18,7 +18,7 @@ Description: Empower your data analysis with 'orbweaver', an R package
package, 'orbweaver' ensures that mutations and changes to
the graph are performed in place, streamlining your
workflow for optimal productivity.
URL: https://github.com/ixpantia/orbweaver
URL: https://github.com/ixpantia/orbweaver-r
BugReports: https://github.com/ixpantia/orbweaver-r/issues
License: MIT + file LICENSE
Encoding: UTF-8
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: vendor document
.PHONY: vendor document covr

vendor:
$(MAKE) -C src/rust vendor
Expand All @@ -12,3 +12,5 @@ install: document
test:
Rscript -e "devtools::test()"

covr:
Rscript -e "covr::report()"
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ S3method(has_children,DirectedAcyclicGraph)
S3method(has_children,DirectedGraph)
S3method(has_parents,DirectedAcyclicGraph)
S3method(has_parents,DirectedGraph)
S3method(least_common_parents,AcyclicDirectedGraph)
S3method(least_common_parents,DirectedAcyclicGraph)
S3method(least_common_parents,DirectedGraph)
S3method(length,DirectedAcyclicGraph)
S3method(length,DirectedGraph)
Expand Down Expand Up @@ -52,7 +52,7 @@ export(graph_to_bin)
export(has_children)
export(has_parents)
export(least_common_parents)
export(new_directed_graph)
export(nodes)
export(parents)
export(populate_edges)
useDynLib(orbweaver, .registration = TRUE)
13 changes: 8 additions & 5 deletions R/bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ graph_to_bin <- function(graph, path) {
}

#' @title Read the graph from a binary blob
#' @param path Path to a file containing a graph binary
#' @param path (Optional) Path to a file containing a graph binary
#' @param bin (Optional) The raw binary of the graph
#' @param type The type of graph the JSON represents
#' @return A graph object
#' @export
Expand All @@ -20,10 +21,12 @@ graph_from_bin <- function(path, bin, type = c("directed", "dag")) {
rlang::abort("Invalid argument `type`")
}
if (!missing(bin)) {
switch(
type[1],
"directed" = DirectedGraph$from_bin_mem(bin),
"dag" = DirectedAcyclicGraph$from_bin_mem(bin)
return(
switch(
type[1],
"directed" = DirectedGraph$from_bin_mem(bin),
"dag" = DirectedAcyclicGraph$from_bin_mem(bin)
)
)
}
if (missing(path)) {
Expand Down
16 changes: 12 additions & 4 deletions R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ DirectedGraph$subset <- function(node_id) .Call(wrap__DirectedGraph__subset, sel

DirectedGraph$print <- function() invisible(.Call(wrap__DirectedGraph__print, self))

DirectedGraph$find_all_paths <- function(`_from`, `_to`) .Call(wrap__DirectedGraph__find_all_paths, self, `_from`, `_to`)

DirectedGraph$to_bin_disk <- function(path) .Call(wrap__DirectedGraph__to_bin_disk, self, path)

DirectedGraph$to_bin_mem <- function() .Call(wrap__DirectedGraph__to_bin_mem, self)
Expand All @@ -49,6 +47,12 @@ DirectedGraph$from_bin_disk <- function(path) .Call(wrap__DirectedGraph__from_bi

DirectedGraph$from_bin_mem <- function(bin) .Call(wrap__DirectedGraph__from_bin_mem, bin)

DirectedGraph$nodes <- function() .Call(wrap__DirectedGraph__nodes, self)

DirectedGraph$length <- function() .Call(wrap__DirectedGraph__length, self)

DirectedGraph$find_all_paths <- function(`_from`, `_to`) .Call(wrap__DirectedGraph__find_all_paths, self, `_from`, `_to`)

#' @export
`$.DirectedGraph` <- function (self, name) { func <- DirectedGraph[[name]]; environment(func) <- environment(); func }

Expand Down Expand Up @@ -81,8 +85,6 @@ DirectedAcyclicGraph$subset <- function(node_id) .Call(wrap__DirectedAcyclicGrap

DirectedAcyclicGraph$print <- function() invisible(.Call(wrap__DirectedAcyclicGraph__print, self))

DirectedAcyclicGraph$find_all_paths <- function(from, to) .Call(wrap__DirectedAcyclicGraph__find_all_paths, self, from, to)

DirectedAcyclicGraph$to_bin_disk <- function(path) .Call(wrap__DirectedAcyclicGraph__to_bin_disk, self, path)

DirectedAcyclicGraph$to_bin_mem <- function() .Call(wrap__DirectedAcyclicGraph__to_bin_mem, self)
Expand All @@ -91,6 +93,12 @@ DirectedAcyclicGraph$from_bin_disk <- function(path) .Call(wrap__DirectedAcyclic

DirectedAcyclicGraph$from_bin_mem <- function(bin) .Call(wrap__DirectedAcyclicGraph__from_bin_mem, bin)

DirectedAcyclicGraph$nodes <- function() .Call(wrap__DirectedAcyclicGraph__nodes, self)

DirectedAcyclicGraph$length <- function() .Call(wrap__DirectedAcyclicGraph__length, self)

DirectedAcyclicGraph$find_all_paths <- function(from, to) .Call(wrap__DirectedAcyclicGraph__find_all_paths, self, from, to)

#' @export
`$.DirectedAcyclicGraph` <- function (self, name) { func <- DirectedAcyclicGraph[[name]]; environment(func) <- environment(); func }

Expand Down
1 change: 0 additions & 1 deletion R/get_leaves.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ get_all_leaves.DirectedGraph <- function(graph, ...) {
get_all_leaves.DirectedAcyclicGraph <- function(graph, ...) {
graph$get_all_leaves()
}

6 changes: 0 additions & 6 deletions R/get_roots.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ get_roots_over <- function(graph, nodes) {

#' @export
get_roots_over.DirectedGraph <- function(graph, nodes) {
if (missing(nodes)) {
return(graph$get_roots_over())
}
graph$get_roots_over(nodes)
}

#' @export
get_roots_over.DirectedAcyclicGraph <- function(graph, nodes) {
if (missing(nodes)) {
return(graph$get_roots_over())
}
graph$get_roots_over(nodes)
}

Expand Down
9 changes: 0 additions & 9 deletions R/graph.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/least_common_parents.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ least_common_parents.DirectedGraph <- function(graph, selected) {
}

#' @export
least_common_parents.AcyclicDirectedGraph <- function(graph, selected) {
least_common_parents.DirectedAcyclicGraph <- function(graph, selected) {
graph$least_common_parents(selected)
}
5 changes: 3 additions & 2 deletions R/length.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#' @export
length.DirectedGraph <- function(x) {
1
x$length()
}

#' @export
length.DirectedAcyclicGraph <- function(x) {
1
x$length()
}

#' @export
length.DirectedGraphBuilder <- function(x) {
rlang::warn("Length of a graph builder is always 1")
1
}
9 changes: 9 additions & 0 deletions R/nodes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#' @title Get the nodes in the graph
#' @description Returns the unique nodes in the graph
#' @param graph A directed or directed acyclic graph
#' @param ... Reserved for later use
#' @return A character vector with the nodes
#' @export
nodes <- function(graph, ...) {
graph$nodes()
}
4 changes: 3 additions & 1 deletion man/graph_from_bin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions man/new_directed_graph.Rd

This file was deleted.

19 changes: 19 additions & 0 deletions man/nodes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/orbweaver-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ name = 'orbweaver'

[dependencies]
extendr-api = { version = "0.6", features = ["serde"] }
orbweaver = { version = "0.9.0" }
orbweaver = { version = "0.10.1" }
Loading

0 comments on commit 2dc78f5

Please sign in to comment.