Commit 34f0834e authored by Facundo Muñoz's avatar Facundo Muñoz ®️
Browse files

read_network(): bugfix check directionality. Warning rather that error.

Fixes #41
parent bbe542b8
Pipeline #11742 passed with stages
in 33 minutes and 59 seconds
Package: mapMCDA Package: mapMCDA
Title: Produce an epidemiological risk map by weighting multiple risk Title: Produce an epidemiological risk map by weighting multiple risk
factors factors
Version: 0.4.50 Version: 0.4.51
Date: 2020-04-29 Date: 2020-04-29
Authors@R: c( person("Andrea", "Apolloni", email = Authors@R: c( person("Andrea", "Apolloni", email =
"andrea.apolloni@cirad.fr", role = c("ctb"), comment = "Animal "andrea.apolloni@cirad.fr", role = c("ctb"), comment = "Animal
......
...@@ -147,11 +147,11 @@ must be respected:", ...@@ -147,11 +147,11 @@ must be respected:",
## Check graph is directed ## Check graph is directed
## At least one edge contains a reciprocal ## At least one edge contains a reciprocal
if( !any(duplicated(rbind(dat[, 1:2], dat[, 2:1]))) ) { if( !any(duplicated(rbind(dat[, 1:2], setNames(dat[, 2:1], names(dat[, 1:2]))))) ) {
stop( warning(
"All the links are unidirectional.\n", "All the links are unidirectional which seems implausible.\n",
"If you are sure that the network is directed, add at least one "Note that mapMCDA works only with directed networks.\n",
reciprocal link with a weight of 0 and proceed." "If you are sure that the network is directed, you can proceed."
) )
} }
......
...@@ -65,14 +65,14 @@ test_that("Interpret network data", { ...@@ -65,14 +65,14 @@ test_that("Interpret network data", {
tf <- tempfile() tf <- tempfile()
write.csv(td, tf, row.names = FALSE) write.csv(td, tf, row.names = FALSE)
n1 <- expect_error(read_network(tf), NA) n1 <- expect_error(suppressWarnings(read_network(tf)), NA)
expect_s3_class(n1, "igraph") expect_s3_class(n1, "igraph")
## Test data with ";" field separator and "," decimal separator ## Test data with ";" field separator and "," decimal separator
tf2 <- tempfile() tf2 <- tempfile()
writeLines(gsub(",", ";", readLines(tf)), file(tf2)) writeLines(gsub(",", ";", readLines(tf)), file(tf2))
writeLines(gsub("\\.", ",", readLines(tf2)), file(tf2)) writeLines(gsub("\\.", ",", readLines(tf2)), file(tf2))
n2 <- expect_error(read_network(tf2), NA) n2 <- expect_error(suppressWarnings(read_network(tf2)), NA)
expect_s3_class(n2, "igraph") expect_s3_class(n2, "igraph")
# all.equal(n1, n2) # all.equal(n1, n2)
...@@ -93,6 +93,27 @@ test_that("Informative errors for incorrectly formatted network data", { ...@@ -93,6 +93,27 @@ test_that("Informative errors for incorrectly formatted network data", {
) )
}) })
test_that("Warning about undirected graphs", {
## Single movement from A to B
df <- data.frame(
orig = "A",
dest = "B",
olon = 1,
olat = 1,
dlon = 2,
dlat = 2,
stringsAsFactors = FALSE
)
tf <- tempfile(fileext = ".csv")
write.csv(df, file = tf, row.names = FALSE)
expect_warning(
read_network(tf),
"All the links are unidirectional"
)
})
test_that("Informative errors for inconsistent network data", { test_that("Informative errors for inconsistent network data", {
## Same locations with different coordinates ## Same locations with different coordinates
...@@ -110,7 +131,7 @@ test_that("Informative errors for inconsistent network data", { ...@@ -110,7 +131,7 @@ test_that("Informative errors for inconsistent network data", {
tf <- tempfile(fileext = ".csv") tf <- tempfile(fileext = ".csv")
write.csv(df, file = tf, row.names = FALSE) write.csv(df, file = tf, row.names = FALSE)
expect_error( expect_error(
read_network(tf), suppressWarnings(read_network(tf)),
"Inconsistent coordinates" "Inconsistent coordinates"
) )
...@@ -131,7 +152,7 @@ test_that("Informative errors for inconsistent network data", { ...@@ -131,7 +152,7 @@ test_that("Informative errors for inconsistent network data", {
tf <- tempfile(fileext = ".csv") tf <- tempfile(fileext = ".csv")
write.csv(df, file = tf, row.names = FALSE) write.csv(df, file = tf, row.names = FALSE)
expect_error( expect_error(
read_network(tf), suppressWarnings(read_network(tf)),
"Detected different locations with the same coordinates." "Detected different locations with the same coordinates."
) )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment