Skip to content

Commit 0d2c2fb

Browse files
committed
no more need for keyword hackery in plotly_build()
1 parent 09aadb4 commit 0d2c2fb

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

R/plotly.R

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -351,26 +351,6 @@ plotly_build <- function(l = last_plot()) {
351351
if (!is.null(a) && !is.null(names(a))) {
352352
x$layout$annotations <- list(x$layout$annotations)
353353
}
354-
# search for keyword args in traces and place them at the top level
355-
kwargs <- lapply(x$data, function(z) z[get_kwargs()])
356-
# 'top-level' keywords args take precedence
357-
kwargs <- Reduce(modifyList, c(kwargs, list(x[get_kwargs()])))
358-
# empty keyword arguments can cause problems
359-
kwargs <- kwargs[sapply(kwargs, length) > 0]
360-
# try our damndest to assign a sensible filename
361-
if (is.null(kwargs$filename)) {
362-
kwargs$filename <-
363-
as.character(kwargs$layout$title) %||%
364-
paste(
365-
c(kwargs$layout$xaxis$title,
366-
kwargs$layout$yaxis$title,
367-
kwargs$layout$zaxis$title),
368-
collapse = " vs. "
369-
) %||%
370-
"plot from api"
371-
}
372-
# tack on keyword arguments
373-
x <- c(x, kwargs)
374354
# traces shouldn't have any names
375355
x$data <- setNames(x$data, NULL)
376356
# add plotly class mainly for printing method

R/plotly_POST.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@
2626

2727
plotly_POST <- function(x, filename, fileopt = "new", world_readable = TRUE) {
2828
x <- plotly_build(x)
29-
if (!missing(filename)) x$filename <- filename
29+
x$filename <- if (!missing(filename)) {
30+
filename
31+
} else {
32+
# try our damndest to assign a sensible filename
33+
x$filename %||% as.character(x$layout$title) %||%
34+
paste(c(x$layout$xaxis$title, x$layout$yaxis$title, x$layout$zaxis$title),
35+
collapse = " vs. ") %||% "plot from api"
36+
}
3037
if (!is.null(x$fileopt))
3138
warning("fileopt was specified in the wrong place. Please specify in plotly_POST()")
3239
x$fileopt <- fileopt

0 commit comments

Comments
 (0)