From a1f06634df17453787c801bc3afa4a454a23ff76 Mon Sep 17 00:00:00 2001 From: schochastics Date: Mon, 3 Mar 2025 14:29:07 +0100 Subject: [PATCH 1/9] changed location for graphdb --- R/foreign.R | 17 +++++++++-------- tests/testthat/_snaps/foreign.md | 29 +++++++++++++++++++++++++++++ tests/testthat/test-foreign.R | 8 ++++++++ 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/R/foreign.R b/R/foreign.R index 04c150230ec..1f02e7c1a80 100644 --- a/R/foreign.R +++ b/R/foreign.R @@ -596,12 +596,13 @@ 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/schochastics/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 +623,10 @@ graph_from_graphdb <- function(url = NULL, typegroup <- typegroups[which(types == type)] if (!prefix %in% prefixes) { - stop("Invalid prefix!") + cli::cli_abort("{prefix} is not a valid prefix. Must be one of {prefixes}.") } if (!type %in% types) { - stop("Invalid graph type!") + cli::cli_abort("{type} is not a valid graph type. Must be one of {types}.") } suff <- if (compressed) ".gz" else "" filename <- paste( @@ -641,7 +642,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:{.arg filename}") } buffer <- read.graph.toraw(f) diff --git a/tests/testthat/_snaps/foreign.md b/tests/testthat/_snaps/foreign.md index 1f4d040c573..347d1764231 100644 --- a/tests/testthat/_snaps/foreign.md +++ b/tests/testthat/_snaps/foreign.md @@ -18,3 +18,32 @@ + 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. 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. 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) +}) From 8394313b0c80b7083897b1d69c8779c9174df42f Mon Sep 17 00:00:00 2001 From: schochastics Date: Wed, 5 Mar 2025 06:04:50 +0100 Subject: [PATCH 2/9] fixed typo in docs --- R/foreign.R | 2 +- man/graph_from_graphdb.Rd | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/foreign.R b/R/foreign.R index 1f02e7c1a80..a6e7323a192 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: diff --git a/man/graph_from_graphdb.Rd b/man/graph_from_graphdb.Rd index 2eed56c7413..9ae08b9b0e4 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/schochastics/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 From d3893c48ffa66d44926d2201002f37bc5d6decd7 Mon Sep 17 00:00:00 2001 From: David Schoch Date: Wed, 5 Mar 2025 06:05:21 +0100 Subject: [PATCH 3/9] split eror message into two lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Maëlle Salmon --- R/foreign.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/foreign.R b/R/foreign.R index a6e7323a192..10c55830995 100644 --- a/R/foreign.R +++ b/R/foreign.R @@ -626,7 +626,10 @@ graph_from_graphdb <- function( cli::cli_abort("{prefix} is not a valid prefix. Must be one of {prefixes}.") } if (!type %in% types) { - cli::cli_abort("{type} is not a valid graph type. Must be one of {types}.") + cli::cli_abort(c( + "{type} is not a valid graph type.", + i = "Must be one of {types}." + )) } suff <- if (compressed) ".gz" else "" filename <- paste( From 99d4e9c0516a863c893089f53d4bfe6c820839f8 Mon Sep 17 00:00:00 2001 From: schochastics Date: Wed, 5 Mar 2025 06:19:01 +0100 Subject: [PATCH 4/9] changed link to igraph org --- R/foreign.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/foreign.R b/R/foreign.R index 10c55830995..a5731a84cf5 100644 --- a/R/foreign.R +++ b/R/foreign.R @@ -599,7 +599,7 @@ write.graph.dot <- function(graph, file, ...) { graph_from_graphdb <- function( url = NULL, prefix = "iso", type = "r001", nodes = NULL, pair = "A", which = 0, - base = "https://github.com/schochastics/graphsdb/raw/refs/heads/main", + base = "https://github.com/igraph/graphsdb/raw/refs/heads/main", compressed = TRUE, directed = TRUE) { if (is.null(nodes) && is.null(url)) { cli::cli_abort("Either {.arg nodes}' or `{.arg url}' must be non-null.") @@ -627,9 +627,9 @@ graph_from_graphdb <- function( } if (!type %in% types) { cli::cli_abort(c( - "{type} is not a valid graph type.", - i = "Must be one of {types}." - )) + "{type} is not a valid graph type.", + i = "Must be one of {types}." + )) } suff <- if (compressed) ".gz" else "" filename <- paste( From 43c67902d4f5d95bc1dab64573981d749da59669 Mon Sep 17 00:00:00 2001 From: schochastics Date: Wed, 5 Mar 2025 07:57:40 +0100 Subject: [PATCH 5/9] updated snapshots --- tests/testthat/_snaps/foreign.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/foreign.md b/tests/testthat/_snaps/foreign.md index 347d1764231..2034059e4ec 100644 --- a/tests/testthat/_snaps/foreign.md +++ b/tests/testthat/_snaps/foreign.md @@ -45,5 +45,6 @@ g <- graph_from_graphdb(nodes = 10, type = "not_existing") Condition Error in `graph_from_graphdb()`: - ! not_existing is not a valid graph type. 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. + ! 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. From 7d457d8980ca998a9aa07dfe4f26c646a7cdea61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Thu, 6 Mar 2025 10:49:30 +0100 Subject: [PATCH 6/9] New function-declaration style --- R/foreign.R | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/R/foreign.R b/R/foreign.R index a5731a84cf5..b5c359d3bed 100644 --- a/R/foreign.R +++ b/R/foreign.R @@ -597,10 +597,16 @@ write.graph.dot <- function(graph, file, ...) { #' @export #' @keywords graphs 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) { + 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)) { cli::cli_abort("Either {.arg nodes}' or `{.arg url}' must be non-null.") } From d21cbe206de3d41fbb22acf6347b301d02cc0921 Mon Sep 17 00:00:00 2001 From: David Schoch Date: Thu, 6 Mar 2025 13:00:07 +0100 Subject: [PATCH 7/9] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kirill Müller --- R/foreign.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/R/foreign.R b/R/foreign.R index b5c359d3bed..109be777a5f 100644 --- a/R/foreign.R +++ b/R/foreign.R @@ -629,12 +629,15 @@ graph_from_graphdb <- function( typegroup <- typegroups[which(types == type)] if (!prefix %in% prefixes) { - cli::cli_abort("{prefix} is not a valid prefix. Must be one of {prefixes}.") + cli::cli_abort(c( + "{.value {prefix}} is not a valid prefix.", + i = "Must be one of {.value {prefixes}}." + )) } if (!type %in% types) { cli::cli_abort(c( - "{type} is not a valid graph type.", - i = "Must be one of {types}." + "{.value {type}} is not a valid graph type.", + i = "Must be one of {.value {types}}." )) } suff <- if (compressed) ".gz" else "" @@ -651,7 +654,7 @@ graph_from_graphdb <- function( f <- try(gzcon(file(filename, open = "rb"))) if (inherits(f, "try-error")) { - cli::cli_abort("Cannot open URL:{.arg filename}") + cli::cli_abort("Cannot open URL provided in {.arg filename}: {.url {filename}}") } buffer <- read.graph.toraw(f) From 6072d2322eae2958074d9b15b6ee04fc73bbb1bf Mon Sep 17 00:00:00 2001 From: schochastics Date: Thu, 6 Mar 2025 13:01:27 +0100 Subject: [PATCH 8/9] updated snapshot --- tests/testthat/_snaps/foreign.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/foreign.md b/tests/testthat/_snaps/foreign.md index 2034059e4ec..731ec2465fa 100644 --- a/tests/testthat/_snaps/foreign.md +++ b/tests/testthat/_snaps/foreign.md @@ -37,7 +37,8 @@ g <- graph_from_graphdb(nodes = 10, prefix = "not_existing") Condition Error in `graph_from_graphdb()`: - ! not_existing is not a valid prefix. Must be one of iso, si6, mcs10, mcs30, mcs50, mcs70, and mcs90. + ! not_existing is not a valid prefix. + i Must be one of iso, si6, mcs10, mcs30, mcs50, mcs70, and mcs90. --- From 0aff4aa56d7fcf4792fc4866536e3895aa158d78 Mon Sep 17 00:00:00 2001 From: schochastics Date: Thu, 6 Mar 2025 13:27:47 +0100 Subject: [PATCH 9/9] fixed doc mismatch --- man/graph_from_graphdb.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/graph_from_graphdb.Rd b/man/graph_from_graphdb.Rd index 9ae08b9b0e4..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 = "https://github.com/schochastics/graphsdb/raw/refs/heads/main", + base = "https://github.com/igraph/graphsdb/raw/refs/heads/main", compressed = TRUE, directed = TRUE )