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

bugfix: tolerate missing values of risk for some epidemiological units

- This can occur for units to small to contain a raster cell centre, or that are small islands

- fixes #32
parent 5c5719ed
Package: mapMCDA
Title: Produce an epidemiological risk map by weighting multiple risk
factors
Version: 0.4.7
Version: 0.4.8
Date: 2019-04-12
Authors@R: c( person("Andrea", "Apolloni", email =
"andrea.apolloni@cirad.fr", role = c("ctb"), comment = "Animal
......
......@@ -84,9 +84,13 @@ risk_unit <- function(r, eu, fun = mean) {
risk_plot <- function(x, v, n) {
x$risk <- v
if (all(is.na(v))) {
stop("Risk values at epidemiological units are all missing.")
}
## Compute risk categories manually, as the default cuts
## in spplot extend beyond the range too much
rv <- range(v)
rv <- range(v, na.rm = TRUE)
## extend the range 0.1 % each side (same as "cut")
rv <- (rv - mean(rv)) * 1.002 + mean(rv)
breaks <- seq(from = rv[1], to = rv[2], length = n + 1)
......
context("test-risk_plot")
polys <- as(GridTopology(c(0,0), c(1,1), c(3,2)), "SpatialPolygons")
# plot(polys)
test_that("Expected plot", {
res <- expect_error(risk_plot(polys, seq_along(polys), n = 2), NA)
expect_is(res, "trellis")
})
test_that("Some NA values are tolerated", {
v <- seq_along(polys)
v[1] <- NA
res <- expect_error(risk_plot(polys, v, n = 2), NA)
expect_is(res, "trellis")
})
test_that("All NA values raise error", {
v <- NA[seq_along(polys)]
expect_error(risk_plot(polys, v, n = 2), "missing")
})
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