Skip to content

Commit f8a9ec6

Browse files
authored
Merge pull request #20 from Displayr/DS-4804-2
DS-4804 Fixup and add unit test
2 parents e74b2cf + b95fd2f commit f8a9ec6

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ README.Rmd
2121
abbvie.R
2222
^\.httr-oauth$
2323
^\.github$
24+
^\.circleci$

R/plotly.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ plot_ly <- function(data = data.frame(), ..., type = NULL, name,
140140
if (!is.data.frame(data) && !crosstalk::is.SharedData(data)) {
141141
stop("First argument, `data`, must be a data frame or shared data.", call. = FALSE)
142142
}
143+
143144
if (is.data.frame(data) && nrow(data) > 0L) {
144145
qtables <- vapply(data, inherits, logical(1L), c("qTable", "QTable"))
145146
if (any(qtables))
146-
data[qtables] <- lapply(data[qtables], unclass)
147+
data[qtables] <- lapply(data[qtables], as.vector)
147148
}
148149

149150
# "native" plotly arguments

tests/testthat/test-plotly.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,19 @@ test_that("Line breaks are properly translated (R -> HTML)", {
358358
test_that("group_by() on a plotly object doesn't produce warning", {
359359
expect_warning(group_by(plot_ly(txhousing), city), NA)
360360
})
361+
362+
test_that("Check QTables dont cause errors", {
363+
s <- data.frame(
364+
x = array(runif(n), dim = n),
365+
x2 = array(runif(n), dim = n),
366+
y = factor(letters[1:10])
367+
)
368+
class(s[[1]]) <- "QTable"
369+
class(s[[2]]) <- "qTable"
370+
expect_error(p <- plot_ly(s) |>
371+
add_segments(x = ~x, xend = ~x2, y = ~y, yend = ~y, showlegend = FALSE) |>
372+
add_markers(x = ~x, xend = ~y, y = ~y, name = "foo", color = I("orange"), showlegend = FALSE) |>
373+
add_markers(x = ~x2, xend = ~y, y = ~y, name = "bar", color = I("blue"), showlegend = FALSE),
374+
NA)
375+
expect_error(print(p), NA)
376+
})

0 commit comments

Comments
 (0)