Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Maintenance - Mise à jour mensuelle Lundi 6 Février entre 7h00 et 9h00
Open sidebar
UMR-ASTRE
mapMCDA
Commits
34f0834e
Commit
34f0834e
authored
Apr 29, 2020
by
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
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
DESCRIPTION
View file @
34f0834e
Package: mapMCDA
Title: Produce an epidemiological risk map by weighting multiple risk
factors
Version: 0.4.5
0
Version: 0.4.5
1
Date: 2020-04-29
Authors@R: c( person("Andrea", "Apolloni", email =
"andrea.apolloni@cirad.fr", role = c("ctb"), comment = "Animal
...
...
R/network.R
View file @
34f0834e
...
...
@@ -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
an
d
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 c
an proceed."
)
}
...
...
tests/testthat/test-load.R
View file @
34f0834e
...
...
@@ -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."
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment