Skip to content

Commit a1c70b4

Browse files
committed
add a simple test
1 parent b6a541e commit a1c70b4

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

R/utils.R

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ add_boxed <- function(x) {
121121
idx <- names(d) %in% get_boxed(d$type %||% "scatter") & sapply(d, length) == 1
122122
if (any(idx)) x$data[[i]][idx] <- lapply(d[idx], I)
123123
# (safely) mark individual nested properties
124-
d$error_x$array <- i(d$error_x$array)
125-
d$error_y$array <- i(d$error_y$array)
126-
d$error_x$arrayminus <- i(d$error_x$arrayminus)
127-
d$error_y$arrayminus <- i(d$error_y$arrayminus)
124+
x$data[[i]]$error_x$array <- i(d$error_x$array)
125+
x$data[[i]]$error_y$array <- i(d$error_y$array)
126+
x$data[[i]]$error_x$arrayminus <- i(d$error_x$arrayminus)
127+
x$data[[i]]$error_y$arrayminus <- i(d$error_y$arrayminus)
128128
}
129129
x
130130
}
@@ -154,22 +154,6 @@ boxers <- list(
154154

155155
i <- function(x) if (is.null(x)) x else I(x)
156156

157-
#' Pick an element from a nested list
158-
#' @param x a list
159-
#' @param nms a character vector specifying a search path
160-
#' @example
161-
#' x <- list(a = list(b = list(c = "Come and get it!")))
162-
#' pick(x, c("a", "b", "c"))
163-
#' #> [1] "Come and get it!"
164-
pick <- function(x, nms) {
165-
for (i in seq_along(nms)) {
166-
nm <- nms[i]
167-
x <- x[[nm]]
168-
}
169-
x
170-
}
171-
172-
173157
rm_asis <- function(x) {
174158
# jsonlite converts NULL to {} and NA to null (plotly prefers null to {})
175159
# https://github.com/jeroenooms/jsonlite/issues/29

tests/testthat/test-plotly.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,12 @@ test_that("inheriting properties works as expected", {
111111
expect_equal(l$data[[2]]$opacity, 0.5)
112112
expect_true(all(l$data[[1]]$y > l$data[[2]]$y))
113113
})
114+
115+
test_that("x/y/z properties have a class of AsIs", {
116+
p <- plot_ly(x = 1, y = 1, z = 1, type = "scatter3d")
117+
l <- plotly_build(p)
118+
tr <- l$data[[1]]
119+
expect_true(inherits(tr$x, "AsIs"))
120+
expect_true(inherits(tr$y, "AsIs"))
121+
expect_true(inherits(tr$z, "AsIs"))
122+
})

0 commit comments

Comments
 (0)