@@ -266,7 +266,7 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02
266
266
}
267
267
268
268
p <- list (
269
- data = Reduce( c , traces ),
269
+ data = unlist( traces , recursive = FALSE ),
270
270
layout = Reduce(modify_list , c(xAxes , rev(yAxes )))
271
271
)
272
272
@@ -275,9 +275,10 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02
275
275
annotations <- Map(reposition , annotations , split(domainInfo , seq_along(plots )))
276
276
shapes <- Map(reposition , shapes , split(domainInfo , seq_along(plots )))
277
277
images <- Map(reposition , images , split(domainInfo , seq_along(plots )))
278
- p $ layout $ annotations <- Reduce(c , annotations )
279
- p $ layout $ shapes <- Reduce(c , shapes )
280
- p $ layout $ images <- Reduce(c , images )
278
+ p $ layout $ annotations <- unlist(annotations , recursive = FALSE )
279
+ p $ layout $ shapes <- unlist(shapes , recursive = FALSE )
280
+ p $ layout $ images <- unlist(images , recursive = FALSE )
281
+
281
282
# merge non-axis layout stuff
282
283
layouts <- lapply(layouts , function (x ) {
283
284
x [! grepl(" ^[x-y]axis|^geo|^mapbox|annotations|shapes|images" , names(x ))] %|| % list ()
@@ -290,8 +291,8 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02
290
291
}
291
292
layouts <- layouts [which_layout ]
292
293
}
293
- p $ attrs <- Reduce( c , lapply(plots , " [[" , " attrs" ))
294
- p $ layout <- modify_list( p $ layout , Reduce(modify_list , layouts ) )
294
+ p $ attrs <- unlist( lapply(plots , " [[" , " attrs" ), recursive = FALSE )
295
+ p $ layout <- Reduce(modify_list , layouts , p $ layout )
295
296
p $ source <- ensure_one(plots , " source" )
296
297
p $ config <- ensure_one(plots , " config" )
297
298
p $ highlight <- ensure_one(plots , " highlight" )
@@ -338,14 +339,18 @@ dots2plots <- function(...) {
338
339
# helper function that warns if more than one plot-level attribute
339
340
# has been specified in a list of plots (and returning that attribute)
340
341
ensure_one <- function (plots , attr ) {
341
- attrs <- lapply(plots , " [" , attr )
342
+ attrs <- Filter(Negate(is.null ), lapply(plots , " [[" , attr ))
343
+ if (length(attrs ) == 0 ) {
344
+ warning(" No " , attr , " found" , call. = FALSE )
345
+ return (NULL )
346
+ }
342
347
for (i in seq_along(attrs )) {
343
348
if (! identical(attrs [[1 ]], attrs [[i ]])) {
344
349
warning(" Can only have one: " , attr , call. = FALSE )
345
350
break
346
351
}
347
352
}
348
- attrs [[length(attrs )]][[ 1 ]]
353
+ attrs [[length(attrs )]]
349
354
}
350
355
351
356
@@ -399,7 +404,7 @@ get_domains <- function(nplots = 1, nrows = 1, margins = 0.01,
399
404
400
405
list2df <- function (x , nms ) {
401
406
# stopifnot(length(unique(sapply(x, length))) == 1)
402
- m <- if (length(x ) == 1 ) t(x [[1 ]]) else Reduce (rbind , x )
407
+ m <- if (length(x ) == 1 ) t(x [[1 ]]) else do.call (rbind , x )
403
408
row.names(m ) <- NULL
404
409
df <- data.frame (m )
405
410
if (! missing(nms )) setNames(df , nms ) else df
0 commit comments