Skip to content

Commit

Permalink
Merge pull request #31 from andyquinterom/prepare_for_cran
Browse files Browse the repository at this point in the history
Prepare for cran
  • Loading branch information
andyquinterom authored Oct 27, 2024
2 parents c1a6660 + 13295d7 commit 926ea9b
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 49 deletions.
5 changes: 3 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.15.0
Version: 0.16.0
Authors@R:
c(person(given = "ixpantia, SRL",
role = "cph",
Expand Down Expand Up @@ -30,7 +30,8 @@ Depends:
R (>= 4.2.0)
Imports:
glue,
rlang
rlang,
methods
Suggests:
testthat (>= 3.0.0),
tibble
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
24 changes: 14 additions & 10 deletions R/bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
)
)
}
12 changes: 7 additions & 5 deletions R/builder.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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
Expand All @@ -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`
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions R/children.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
4 changes: 4 additions & 0 deletions R/error.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
throw_if_error <- function(res) {
if (methods::is(res, "error")) rlang::abort(res$value)
return(res)
}
8 changes: 4 additions & 4 deletions R/find_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/get_leaves.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions R/get_roots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
}
4 changes: 2 additions & 2 deletions R/has_children.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
4 changes: 2 additions & 2 deletions R/has_parents.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
4 changes: 2 additions & 2 deletions R/least_common_parents.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
4 changes: 2 additions & 2 deletions R/parents.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
4 changes: 2 additions & 2 deletions R/subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
6 changes: 3 additions & 3 deletions src/rust/Cargo.lock

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

6 changes: 3 additions & 3 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = 'orbweaver_r'
version = '0.15.0'
version = '0.16.0'
edition = '2021'

[lib]
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
Expand Down
Binary file modified src/rust/vendor.tar.xz
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/testthat/test-has_parents.R
Original file line number Diff line number Diff line change
@@ -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"))
})

0 comments on commit 926ea9b

Please sign in to comment.