Skip to content

Commit b6a541e

Browse files
committed
(safely) mark individual nested properties
1 parent aa19087 commit b6a541e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

R/utils.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ add_boxed <- function(x) {
120120
d <- x$data[[i]]
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)
123+
# (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)
123128
}
124129
x
125130
}
@@ -147,6 +152,23 @@ boxers <- list(
147152
surface = c("x", "y", "z", "text")
148153
)
149154

155+
i <- function(x) if (is.null(x)) x else I(x)
156+
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+
150172

151173
rm_asis <- function(x) {
152174
# jsonlite converts NULL to {} and NA to null (plotly prefers null to {})

0 commit comments

Comments
 (0)