Skip to content

Commit

Permalink
Merge pull request #1638 from wfjvdham/check_NA_for_lines
Browse files Browse the repository at this point in the history
Do not create structure with NULL to remove warnings
  • Loading branch information
cpsievert authored Oct 21, 2019
2 parents c299c5f + 599b851 commit 5e1feb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions R/plotly_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,12 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
)
for (i in x$.plotlyVariableMapping) {
# try to reduce the amount of data we have to send for non-positional scales
x[[i]] <- structure(
if (i %in% npscales()) uniq(d[[i]]) else d[[i]],
class = oldClass(x[[i]])
)
entry <- if (i %in% npscales()) uniq(d[[i]]) else d[[i]]
if (is.null(entry)) {
x[[i]] <- NULL
} else {
x[[i]] <- structure(entry, class = oldClass(x[[i]]))
}
}
x
})
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-ggplot-lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,10 @@ test_that("geom_linerange() without a y aesthetic translates to a path", {
)

})

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

0 comments on commit 5e1feb3

Please sign in to comment.