diff --git a/R/foreign.R b/R/foreign.R index 04c150230ec..109be777a5f 100644 --- a/R/foreign.R +++ b/R/foreign.R @@ -548,7 +548,7 @@ write.graph.dot <- function(graph, file, ...) { #' Load a graph from the graph database for testing graph isomorphism. #' #' This function downloads a graph from a database created for the evaluation -#' of graph isomorphism testing algothitms. +#' of graph isomorphism testing algorithms. #' #' `graph_from_graphdb()` reads a graph from the graph database from an FTP or #' HTTP server or from a local copy. It has two modes of operation: @@ -596,12 +596,19 @@ write.graph.dot <- function(graph, file, ...) { #' @family foreign #' @export #' @keywords graphs -graph_from_graphdb <- function(url = NULL, - prefix = "iso", type = "r001", nodes = NULL, pair = "A", which = 0, - base = "http://cneurocvs.rmki.kfki.hu/graphdb/gzip", - compressed = TRUE, directed = TRUE) { +graph_from_graphdb <- function( + url = NULL, + prefix = "iso", + type = "r001", + nodes = NULL, + pair = "A", + which = 0, + base = "https://github.com/igraph/graphsdb/raw/refs/heads/main", + compressed = TRUE, + directed = TRUE +) { if (is.null(nodes) && is.null(url)) { - stop("The `nodes' or the `url' argument must be non-null") + cli::cli_abort("Either {.arg nodes}' or `{.arg url}' must be non-null.") } if (is.null(url)) { @@ -622,10 +629,16 @@ graph_from_graphdb <- function(url = NULL, typegroup <- typegroups[which(types == type)] if (!prefix %in% prefixes) { - stop("Invalid prefix!") + cli::cli_abort(c( + "{.value {prefix}} is not a valid prefix.", + i = "Must be one of {.value {prefixes}}." + )) } if (!type %in% types) { - stop("Invalid graph type!") + cli::cli_abort(c( + "{.value {type}} is not a valid graph type.", + i = "Must be one of {.value {types}}." + )) } suff <- if (compressed) ".gz" else "" filename <- paste( @@ -641,7 +654,7 @@ graph_from_graphdb <- function(url = NULL, f <- try(gzcon(file(filename, open = "rb"))) if (inherits(f, "try-error")) { - stop(paste("Cannot open URL:", filename)) + cli::cli_abort("Cannot open URL provided in {.arg filename}: {.url {filename}}") } buffer <- read.graph.toraw(f) diff --git a/man/graph_from_graphdb.Rd b/man/graph_from_graphdb.Rd index 2eed56c7413..a875b054b36 100644 --- a/man/graph_from_graphdb.Rd +++ b/man/graph_from_graphdb.Rd @@ -11,7 +11,7 @@ graph_from_graphdb( nodes = NULL, pair = "A", which = 0, - base = "http://cneurocvs.rmki.kfki.hu/graphdb/gzip", + base = "https://github.com/igraph/graphsdb/raw/refs/heads/main", compressed = TRUE, directed = TRUE ) @@ -52,7 +52,7 @@ A new graph object. } \description{ This function downloads a graph from a database created for the evaluation -of graph isomorphism testing algothitms. +of graph isomorphism testing algorithms. } \details{ \code{graph_from_graphdb()} reads a graph from the graph database from an FTP or diff --git a/tests/testthat/_snaps/foreign.md b/tests/testthat/_snaps/foreign.md index 1f4d040c573..731ec2465fa 100644 --- a/tests/testthat/_snaps/foreign.md +++ b/tests/testthat/_snaps/foreign.md @@ -18,3 +18,34 @@ + edges (vertex names): [1] 0--1 1--2 +# graph_from_graphdb works + + Code + g <- graph_from_graphdb(nodes = 1000) + +--- + + Code + g <- graph_from_graphdb() + Condition + Error in `graph_from_graphdb()`: + ! Either `nodes`' or ``url`' must be non-null. + +--- + + Code + g <- graph_from_graphdb(nodes = 10, prefix = "not_existing") + Condition + Error in `graph_from_graphdb()`: + ! not_existing is not a valid prefix. + i Must be one of iso, si6, mcs10, mcs30, mcs50, mcs70, and mcs90. + +--- + + Code + g <- graph_from_graphdb(nodes = 10, type = "not_existing") + Condition + Error in `graph_from_graphdb()`: + ! not_existing is not a valid graph type. + i Must be one of r001, r005, r01, r02, m2D, m2Dr2, m2Dr4, m2Dr6, m3D, m3Dr2, m3Dr4, m3Dr6, m4D, m4Dr2, m4Dr4, m4Dr6, b03, b03m, ..., b09, and b09m. + diff --git a/tests/testthat/test-foreign.R b/tests/testthat/test-foreign.R index 31713d0d00a..c75ac0fa53a 100644 --- a/tests/testthat/test-foreign.R +++ b/tests/testthat/test-foreign.R @@ -38,3 +38,11 @@ test_that("reading graph in LGL format", { write_graph(g, lgl_path, "lgl") expect_snapshot(read_graph(lgl_path, "lgl")) }) + +test_that("graph_from_graphdb works", { + skip_on_cran() + expect_snapshot(g <- graph_from_graphdb(nodes = 1000)) + expect_snapshot(g <- graph_from_graphdb(), error = TRUE) + expect_snapshot(g <- graph_from_graphdb(nodes = 10, prefix = "not_existing"), error = TRUE) + expect_snapshot(g <- graph_from_graphdb(nodes = 10, type = "not_existing"), error = TRUE) +})