diff --git a/DESCRIPTION b/DESCRIPTION index 9470050..545a404 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: orbweaver Title: Fast and Efficient Graph Data Structures -Version: 0.15.0 +Version: 0.16.0 Authors@R: c(person(given = "ixpantia, SRL", role = "cph", @@ -30,7 +30,8 @@ Depends: R (>= 4.2.0) Imports: glue, - rlang + rlang, + methods Suggests: testthat (>= 3.0.0), tibble diff --git a/Makefile b/Makefile index 37f8120..94398eb 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,13 @@ vendor: $(MAKE) -C src/rust vendor document: - Rscript -e "rextendr::document()" + NOT_CRAN="true" Rscript -e "rextendr::document()" install: document - Rscript -e "devtools::install()" + NOT_CRAN="true" Rscript -e "devtools::install()" test: - Rscript -e "devtools::test()" + NOT_CRAN="true" Rscript -e "devtools::test()" covr: - Rscript -e "covr::report()" + NOT_CRAN="true" Rscript -e "covr::report()" diff --git a/R/bin.R b/R/bin.R index 6a79643..2d9d492 100644 --- a/R/bin.R +++ b/R/bin.R @@ -5,9 +5,9 @@ #' @export graph_to_bin <- function(graph, path) { if (missing(path)) { - return(graph$to_bin_mem()) + return(throw_if_error(graph$to_bin_mem())) } - graph$to_bin_disk(path) + throw_if_error(graph$to_bin_disk(path)) } #' @title Read the graph from a binary blob @@ -22,19 +22,23 @@ graph_from_bin <- function(path, bin, type = c("directed", "dag")) { } if (!missing(bin)) { return( - switch( - type[1], - "directed" = DirectedGraph$from_bin_mem(bin), - "dag" = DirectedAcyclicGraph$from_bin_mem(bin) + throw_if_error( + switch( + type[1], + "directed" = DirectedGraph$from_bin_mem(bin), + "dag" = DirectedAcyclicGraph$from_bin_mem(bin) + ) ) ) } if (missing(path)) { rlang::abort("Must provide `path` or `bin` arguments") } - switch( - type[1], - "directed" = DirectedGraph$from_bin_disk(path), - "dag" = DirectedAcyclicGraph$from_bin_disk(path) + throw_if_error( + switch( + type[1], + "directed" = DirectedGraph$from_bin_disk(path), + "dag" = DirectedAcyclicGraph$from_bin_disk(path) + ) ) } diff --git a/R/builder.R b/R/builder.R index 8899002..9502060 100644 --- a/R/builder.R +++ b/R/builder.R @@ -18,7 +18,7 @@ graph_builder <- function(type = "directed") { #' @return The updated graph builder object #' @export add_edge <- function(graph_builder, from, to) { - graph_builder$add_edge(from, to) + throw_if_error(graph_builder$add_edge(from, to)) return(graph_builder) } @@ -33,7 +33,7 @@ add_edge <- function(graph_builder, from, to) { #' @return The updated graph builder object #' @export add_path <- function(graph_builder, path) { - graph_builder$add_path(path) + throw_if_error(graph_builder$add_path(path)) return(graph_builder) } @@ -50,7 +50,7 @@ add_path <- function(graph_builder, path) { #' @return A DirectedGraph Object #' @export build_directed <- function(graph_builder) { - graph_builder$build_directed() + throw_if_error(graph_builder$build_directed()) } #' @title Build a DirectedAcyclicGraph from a builder @@ -64,7 +64,7 @@ build_directed <- function(graph_builder) { #' @return A DirectedAcyclicGraph Object #' @export build_acyclic <- function(graph_builder) { - graph_builder$build_acyclic() + throw_if_error(graph_builder$build_acyclic()) } #' @title Populates the edges of a graph from a `tibble` @@ -88,6 +88,8 @@ populate_edges <- function(graph_builder, edges_df, parent_col, child_col) { rlang::abort(glue::glue("Column {child_col} is not of class `character`")) } - rs_populate_edges_builder(graph_builder, parent_iter, child_iter) + throw_if_error( + rs_populate_edges_builder(graph_builder, parent_iter, child_iter) + ) return(graph_builder) } diff --git a/R/children.R b/R/children.R index 6494fa3..ef1ef32 100644 --- a/R/children.R +++ b/R/children.R @@ -13,10 +13,10 @@ children <- function(graph, nodes) { #' @export children.DirectedGraph <- function(graph, nodes) { - graph$children(nodes) + throw_if_error(graph$children(nodes)) } #' @export children.DirectedAcyclicGraph <- function(graph, nodes) { - graph$children(nodes) + throw_if_error(graph$children(nodes)) } diff --git a/R/error.R b/R/error.R new file mode 100644 index 0000000..e11c493 --- /dev/null +++ b/R/error.R @@ -0,0 +1,4 @@ +throw_if_error <- function(res) { + if (methods::is(res, "error")) rlang::abort(res$value) + return(res) +} diff --git a/R/find_path.R b/R/find_path.R index cd19007..ff53ddd 100644 --- a/R/find_path.R +++ b/R/find_path.R @@ -20,12 +20,12 @@ find_path <- function(graph, from, to) { #' @export find_path.DirectedGraph <- function(graph, from, to) { - graph$find_path(from, to) + throw_if_error(graph$find_path(from, to)) } #' @export find_path.DirectedAcyclicGraph <- function(graph, from, to) { - graph$find_path(from, to) + throw_if_error(graph$find_path(from, to)) } #' @title Find all paths between two nodes @@ -46,12 +46,12 @@ find_all_paths <- function(graph, from, to) { #' @export find_all_paths.DirectedGraph <- function(graph, from, to) { - graph$find_all_paths(from, to) + throw_if_error(graph$find_all_paths(from, to)) } #' @export find_all_paths.DirectedAcyclicGraph <- function(graph, from, to) { - graph$find_all_paths(from, to) + throw_if_error(graph$find_all_paths(from, to)) } #' @title Find the shortest path from one node to many diff --git a/R/get_leaves.R b/R/get_leaves.R index 0e76f07..3f10b96 100644 --- a/R/get_leaves.R +++ b/R/get_leaves.R @@ -14,12 +14,12 @@ get_leaves_under <- function(graph, nodes) { #' @export get_leaves_under.DirectedGraph <- function(graph, nodes) { - graph$get_leaves_under(nodes) + throw_if_error(graph$get_leaves_under(nodes)) } #' @export get_leaves_under.DirectedAcyclicGraph <- function(graph, nodes) { - graph$get_leaves_under(nodes) + throw_if_error(graph$get_leaves_under(nodes)) } #' @title Get all the leaf nodes of a graph diff --git a/R/get_roots.R b/R/get_roots.R index 22ecb9a..4e70637 100644 --- a/R/get_roots.R +++ b/R/get_roots.R @@ -14,12 +14,12 @@ get_roots_over <- function(graph, nodes) { #' @export get_roots_over.DirectedGraph <- function(graph, nodes) { - graph$get_roots_over(nodes) + throw_if_error(graph$get_roots_over(nodes)) } #' @export get_roots_over.DirectedAcyclicGraph <- function(graph, nodes) { - graph$get_roots_over(nodes) + throw_if_error(graph$get_roots_over(nodes)) } #' @title Get the all the root nodes of a graph @@ -37,10 +37,10 @@ get_all_roots <- function(graph, ...) { #' @export get_all_roots.DirectedGraph <- function(graph, ...) { - graph$get_all_roots() + throw_if_error(graph$get_all_roots()) } #' @export get_all_roots.DirectedAcyclicGraph <- function(graph, ...) { - graph$get_all_roots() + throw_if_error(graph$get_all_roots()) } diff --git a/R/has_children.R b/R/has_children.R index 496903a..58b3a8f 100644 --- a/R/has_children.R +++ b/R/has_children.R @@ -12,10 +12,10 @@ has_children <- function(graph, nodes) { #' @export has_children.DirectedGraph <- function(graph, nodes) { - graph$has_children(nodes) + throw_if_error(graph$has_children(nodes)) } #' @export has_children.DirectedAcyclicGraph <- function(graph, nodes) { - graph$has_children(nodes) + throw_if_error(graph$has_children(nodes)) } diff --git a/R/has_parents.R b/R/has_parents.R index 9b0d477..93fe719 100644 --- a/R/has_parents.R +++ b/R/has_parents.R @@ -12,10 +12,10 @@ has_parents <- function(graph, nodes) { #' @export has_parents.DirectedGraph <- function(graph, nodes) { - graph$has_parents(nodes) + throw_if_error(graph$has_parents(nodes)) } #' @export has_parents.DirectedAcyclicGraph <- function(graph, nodes) { - graph$has_parents(nodes) + throw_if_error(graph$has_parents(nodes)) } diff --git a/R/least_common_parents.R b/R/least_common_parents.R index 2a3a3bb..c830b4c 100644 --- a/R/least_common_parents.R +++ b/R/least_common_parents.R @@ -12,10 +12,10 @@ least_common_parents <- function(graph, selected) { #' @export least_common_parents.DirectedGraph <- function(graph, selected) { - graph$least_common_parents(selected) + throw_if_error(graph$least_common_parents(selected)) } #' @export least_common_parents.DirectedAcyclicGraph <- function(graph, selected) { - graph$least_common_parents(selected) + throw_if_error(graph$least_common_parents(selected)) } diff --git a/R/parents.R b/R/parents.R index c77b035..99aa06e 100644 --- a/R/parents.R +++ b/R/parents.R @@ -13,10 +13,10 @@ parents <- function(graph, nodes) { #' @export parents.DirectedGraph <- function(graph, nodes) { - graph$parents(nodes) + throw_if_error(graph$parents(nodes)) } #' @export parents.DirectedAcyclicGraph <- function(graph, nodes) { - graph$parents(nodes) + throw_if_error(graph$parents(nodes)) } diff --git a/R/subset.R b/R/subset.R index 8a3ae59..9d2a968 100644 --- a/R/subset.R +++ b/R/subset.R @@ -4,7 +4,7 @@ subset.DirectedGraph <- function(x, ...) { if (length(arguments) > 1) { rlang::abort("Currently only one node is supported for subset") } - x$subset(arguments) + throw_if_error(x$subset(arguments)) } #' @export @@ -13,5 +13,5 @@ subset.DirectedAcyclicGraph <- function(x, ...) { if (length(arguments) > 1) { rlang::abort("Currently only one node is supported for subset") } - x$subset(arguments) + throw_if_error(x$subset(arguments)) } diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock index 39cff0d..0d9280e 100644 --- a/src/rust/Cargo.lock +++ b/src/rust/Cargo.lock @@ -132,9 +132,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "orbweaver" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbeaad559ff389ba4afe076543487a2c9563bdaa5b58ab324f5c2136a1630c75" +checksum = "9c80cca0f07aaf76960b876f1b18625af5c8d8dd99b50422a138519bd6e423aa" dependencies = [ "flate2", "fxhash", @@ -145,7 +145,7 @@ dependencies = [ [[package]] name = "orbweaver_r" -version = "0.15.0" +version = "0.16.0" dependencies = [ "extendr-api", "orbweaver", diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml index 175fb99..1602280 100644 --- a/src/rust/Cargo.toml +++ b/src/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'orbweaver_r' -version = '0.15.0' +version = '0.16.0' edition = '2021' [lib] @@ -8,8 +8,8 @@ crate-type = [ 'staticlib', 'lib' ] name = 'orbweaver_r' [dependencies] -extendr-api = { version = "0.7", features = ["serde"] } -orbweaver = { version = "0.15" } +orbweaver = { version = "0.16" } +extendr-api = { version = "0.7", features = ["serde", "result_condition"] } # This will help us filter the platforms # we support to make the final bundle size diff --git a/src/rust/vendor.tar.xz b/src/rust/vendor.tar.xz index 680d3d5..6401a11 100644 Binary files a/src/rust/vendor.tar.xz and b/src/rust/vendor.tar.xz differ diff --git a/tests/testthat/test-has_parents.R b/tests/testthat/test-has_parents.R new file mode 100644 index 0000000..d442848 --- /dev/null +++ b/tests/testthat/test-has_parents.R @@ -0,0 +1,8 @@ +test_that("has_parent on non existing node should error", { + graph <- graph_builder() |> + add_path(c("1", "2", "3")) |> + build_directed() + + expect_equal(has_parents(graph, "3"), TRUE) + expect_error(has_parents(graph, "4")) +})