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
Title: Produce an epidemiological risk map by weighting multiple risk
factors
Version: 0.4.50
Version: 0.4.51
Date: 2020-04-29
Authors@R: c( person("Andrea", "Apolloni", email =
"andrea.apolloni@cirad.fr", role = c("ctb"), comment = "Animal
......
......@@ -147,11 +147,11 @@ must be respected:",
## Check graph is directed
## At least one edge contains a reciprocal
if( !any(duplicated(rbind(dat[, 1:2], dat[, 2:1]))) ) {
stop(
"All the links are unidirectional.\n",
"If you are sure that the network is directed, add at least one
reciprocal link with a weight of 0 and proceed."
if( !any(duplicated(rbind(dat[, 1:2], setNames(dat[, 2:1], names(dat[, 1:2]))))) ) {
warning(
"All the links are unidirectional which seems implausible.\n",
"Note that mapMCDA works only with directed networks.\n",
"If you are sure that the network is directed, you can proceed."
)
}
......
......@@ -65,14 +65,14 @@ test_that("Interpret network data", {
tf <- tempfile()
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")
## Test data with ";" field separator and "," decimal separator
tf2 <- tempfile()
writeLines(gsub(",", ";", readLines(tf)), 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")
# all.equal(n1, n2)
......@@ -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", {
## Same locations with different coordinates
......@@ -110,7 +131,7 @@ test_that("Informative errors for inconsistent network data", {
tf <- tempfile(fileext = ".csv")
write.csv(df, file = tf, row.names = FALSE)
expect_error(
read_network(tf),
suppressWarnings(read_network(tf)),
"Inconsistent coordinates"
)
......@@ -131,7 +152,7 @@ test_that("Informative errors for inconsistent network data", {
tf <- tempfile(fileext = ".csv")
write.csv(df, file = tf, row.names = FALSE)
expect_error(
read_network(tf),
suppressWarnings(read_network(tf)),
"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