Skip to content

Commit

Permalink
Fix for issue #12, allow fetching no nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
oneilsh committed Apr 9, 2024
1 parent 1f78b92 commit 4021b6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions R/tbl_kgx.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
#' @export
#' @importFrom tidygraph tbl_graph
tbl_kgx <- function(nodes = NULL, edges = NULL, ...) {
# nodes can be empty, if so we need to create an empty data frame
if(nrow(nodes) == 0) {
nodes <- data.frame(id = character(0))
nodes$category <- list()
edges <- data.frame(subject = character(0), predicate = character(0), object = character(0))
}

if(is.null(nodes$id)) { stop("Error: tbl_kgx nodes must have an 'id' column.") }
if(is.null(nodes$id)) { stop("Error: tbl_kgx nodes must have an 'category' column.") }

Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ library(testthat)
library(assertthat)
library(tidyr)

test_that("fetch_edges with no return results works", {
eds_hits <- query_ids(c("WB:WBGene00008083")) # no associations
g <- eds_hits %>% fetch_edges(result_categories = "biolink:Disease")
})

test_that("fetch_edges works as expected", {
testthat::skip("temporary skip")

Expand Down

0 comments on commit 4021b6d

Please sign in to comment.