Skip to content

Commit 4088ee6

Browse files
committed
Update metadata condition and add test
1 parent 1ef8ff1 commit 4088ee6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,23 @@ test_that("simple county bubble plot", {
116116
suppressWarnings(
117117
plot(fb_county, plot_type = "bubble")))
118118
})
119+
120+
121+
test_that("test 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")
132+
)
133+
134+
expect_warning(plot(fake_data),
135+
"Metadata for signal mean and standard deviation not",
136+
"available; defaulting to observed mean and standard",
137+
"deviation to set plot range.")
138+
})

0 commit comments

Comments
 (0)