diff --git a/R/tbl_kgx.R b/R/tbl_kgx.R index 3f7624f..ee19ccf 100644 --- a/R/tbl_kgx.R +++ b/R/tbl_kgx.R @@ -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.") } diff --git a/tests/testthat/test-fetch.R b/tests/testthat/test-fetch.R index 7511e0b..ebe3bc2 100644 --- a/tests/testthat/test-fetch.R +++ b/tests/testthat/test-fetch.R @@ -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")