Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
UMR-ASTRE
mapMCDA
Commits
a4b061a8
Commit
a4b061a8
authored
Apr 25, 2020
by
Facundo Muñoz
®️
Browse files
read_network(): aggregate volumes for multiple links
parent
71b6904b
Changes
3
Hide whitespace changes
Inline
Side-by-side
DESCRIPTION
View file @
a4b061a8
Package: mapMCDA
Title: Produce an epidemiological risk map by weighting multiple risk
factors
Version: 0.4.4
5
Version: 0.4.4
7
Date: 2020-04-25
Authors@R: c( person("Andrea", "Apolloni", email =
"andrea.apolloni@cirad.fr", role = c("ctb"), comment = "Animal
...
...
R/network.R
View file @
a4b061a8
...
...
@@ -126,8 +126,23 @@ must be respected:",
## Check duplicated edges
if
(
any
(
idx
<-
duplicated
(
dat
[,
1
:
2
]))
)
{
print
(
dat
[
which
(
idx
),
1
:
2
])
stop
(
"The links above appear more than once"
)
if
(
nc
==
6L
)
{
## No volume. Just remove duplicated lines
dat
<-
dat
[
!
duplicated
(
dat
),]
}
else
{
## Aggregate volume with warning
warning
(
"Aggregating volumes for multiple links."
,
"If this is not what you want, stop now and aggregate manually."
)
dat
<-
aggregate
(
dat
[,
7
],
by
=
dat
[,
1
:
6
],
FUN
=
"sum"
)
}
}
## Check graph is directed
...
...
tests/testthat/test-load.R
View file @
a4b061a8
...
...
@@ -92,3 +92,33 @@ test_that("Informative errors for incorrectly formatted network data", {
"Expected 6 or 7 columns"
)
})
test_that
(
"read_network aggregates volume for multiple links"
,
{
base_df
<-
data.frame
(
orig
=
rep
(
letters
[
1
:
4
]),
dest
=
rep
(
letters
[
4
:
1
]),
olon
=
rep
(
1
:
4
),
olat
=
rep
(
1
:
4
),
dlon
=
rep
(
4
:
1
),
dlat
=
rep
(
4
:
1
),
vol
=
10
*
1
:
4
,
stringsAsFactors
=
FALSE
)
df
<-
rbind
(
base_df
,
base_df
,
base_df
)
tf
<-
tempfile
(
fileext
=
".csv"
)
write.csv
(
df
,
file
=
tf
,
row.names
=
FALSE
)
expect_warning
(
res
<-
read_network
(
tf
),
"Aggregating volumes"
)
expect_equal
(
as_data_frame
(
res
),
transform
(
base_df
[,
-
(
3
:
6
)],
vol
=
3
*
vol
)[
order
(
base_df
$
vol
,
decreasing
=
TRUE
),],
check.attributes
=
FALSE
)
})
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