Skip to content

Commit 06ef5fc

Browse files
authored
Merge pull request #326 from cmu-delphi/update-meta-check
Update R plotting metadata check
2 parents 1ef8ff1 + eec983e commit 06ef5fc

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

R-packages/covidcast/DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ Suggests:
6060
tibble,
6161
vdiffr
6262
VignetteBuilder: knitr
63+
Config/testthat/edition: 3

R-packages/covidcast/R/plot.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ plot.covidcast_signal = function(x, plot_type = c("choro", "bubble", "line"),
110110
# For the maps, set range, if we need to (to mean +/- 3 standard deviations,
111111
# from metadata)
112112
if (is.null(range) && (plot_type == "choro" || plot_type == "bubble")) {
113-
if (is.null(attributes(x)$metadata)) {
113+
if (is.null(attributes(x)$metadata$mean_value) ||
114+
is.null(attributes(x)$metadata$stdev_value)) {
114115
warn(paste("Metadata for signal mean and standard deviation not",
115116
"available; defaulting to observed mean and standard",
116117
"deviation to set plot range."),

R-packages/covidcast/tests/testthat/test-plot.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,24 @@ test_that("simple county bubble plot", {
116116
suppressWarnings(
117117
plot(fb_county, plot_type = "bubble")))
118118
})
119+
120+
121+
test_that("warn on incomplete metadata", {
122+
fake_data <- structure(data.frame(
123+
data_source = "foo",
124+
signal = "bar",
125+
value = c(1, 2, 0, 3),
126+
geo_value = c("pa", "in", "tx", "wy"),
127+
time_value = as.Date("2020-01-01"),
128+
issue = as.Date("2020-02-01"),
129+
stderr = 0.5),
130+
class = c("covidcast_signal", "data.frame"),
131+
metadata = list(geo_type = "state", mean_value = 0, stdev_value = 1)
132+
)
133+
134+
expect_warning(plot(fake_data), NA)
135+
attributes(fake_data)$metadata = list(geo_type = "state", mean_value = 0)
136+
137+
expect_warning(plot(fake_data),
138+
class="covidcast_plot_meta_not_found")
139+
})

0 commit comments

Comments
 (0)