Skip to content

Commit 5e1feb3

Browse files
authored
Merge pull request #1638 from wfjvdham/check_NA_for_lines
Do not create structure with NULL to remove warnings
2 parents c299c5f + 599b851 commit 5e1feb3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

R/plotly_build.R

+6-4
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,12 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
280280
)
281281
for (i in x$.plotlyVariableMapping) {
282282
# try to reduce the amount of data we have to send for non-positional scales
283-
x[[i]] <- structure(
284-
if (i %in% npscales()) uniq(d[[i]]) else d[[i]],
285-
class = oldClass(x[[i]])
286-
)
283+
entry <- if (i %in% npscales()) uniq(d[[i]]) else d[[i]]
284+
if (is.null(entry)) {
285+
x[[i]] <- NULL
286+
} else {
287+
x[[i]] <- structure(entry, class = oldClass(x[[i]]))
288+
}
287289
}
288290
x
289291
})

tests/testthat/test-ggplot-lines.R

+7
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,10 @@ test_that("geom_linerange() without a y aesthetic translates to a path", {
120120
)
121121

122122
})
123+
124+
test_that("NA values do not cause a lot of warnings when ploting (#1299)", {
125+
df <- data.frame(x=1:2, y=NA)
126+
p <- plot_ly(df, x=~x, y=~y)
127+
expect_warning(plotly_build(p), "Ignoring")
128+
expect_failure(expect_warning(plotly_build(p), "structure"))
129+
})

0 commit comments

Comments
 (0)