Skip to content

Commit 9bc585a

Browse files
cpsievertjulianstanleyjulistanley
authored
Dplyr 1.0 (#1821)
* update dplyr functions to use non-standard evaluation * Typo: unquote rlang::sym For some reason, all tests passed without catching this mistake, but I think I should have had a !! here. * Same fix as previous commit (d2bc923) * missed an add --> .add * lapply(vars, sym)-->syms(vars) Co-authored-by: Carson Sievert <cpsievert1@gmail.com> * Revert imports.R * Use group_by_add; dots_as_quosures * as_quosure --> new_quosure As is done here https://github.com/r-lib/rlang/blob/64df8e3f/R/compat-lazyeval.R#L51 Co-authored-by: Carson Sievert <cpsievert1@gmail.com> * Remove redundant add arguments to group_by_add * Proper registration plotly methods for dplyr generics * ensure that crosstalk set attribute is preserved when applying dplyr transforms, closes #1825, closes #1799 * make highlight_key() an S3 generic that understands plotly objects * review feedback * clean-up docs Co-authored-by: julianstanley <stanley.ju@husky.neu.edu> Co-authored-by: Julian Stanley <julianst@mit.edu>
1 parent 1d1eddd commit 9bc585a

15 files changed

+225
-115
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Imports:
4040
hexbin,
4141
RColorBrewer,
4242
dplyr,
43+
vctrs,
4344
tibble,
4445
lazyeval (>= 0.2.0),
4546
rlang,
@@ -75,7 +76,7 @@ Suggests:
7576
forcats,
7677
thematic
7778
LazyData: true
78-
RoxygenNote: 7.1.0
79+
RoxygenNote: 7.1.1
7980
Encoding: UTF-8
8081
Roxygen: list(markdown = TRUE)
8182
Remotes:

NAMESPACE

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
S3method(api_create,data.frame)
44
S3method(api_create,ggplot)
55
S3method(api_create,plotly)
6-
S3method(arrange_,plotly)
7-
S3method(distinct_,plotly)
8-
S3method(do_,plotly)
96
S3method(embed_notebook,plotly)
10-
S3method(filter_,plotly)
117
S3method(fortify,SharedData)
128
S3method(geom2trace,GeomBar)
139
S3method(geom2trace,GeomBlank)
@@ -25,12 +21,11 @@ S3method(ggplotly,"NULL")
2521
S3method(ggplotly,ggmatrix)
2622
S3method(ggplotly,ggplot)
2723
S3method(ggplotly,plotly)
28-
S3method(group_by_,plotly)
29-
S3method(groups,plotly)
24+
S3method(highlight_key,default)
25+
S3method(highlight_key,plotly)
3026
S3method(layout,matrix)
3127
S3method(layout,plotly)
3228
S3method(layout,shiny.tag.list)
33-
S3method(mutate_,plotly)
3429
S3method(plotly_build,"NULL")
3530
S3method(plotly_build,gg)
3631
S3method(plotly_build,list)
@@ -40,10 +35,6 @@ S3method(print,api_grid)
4035
S3method(print,api_grid_local)
4136
S3method(print,api_plot)
4237
S3method(print,plotly_data)
43-
S3method(rename_,plotly)
44-
S3method(select_,plotly)
45-
S3method(slice_,plotly)
46-
S3method(summarise_,plotly)
4738
S3method(to_basic,GeomAbline)
4839
S3method(to_basic,GeomAnnotationMap)
4940
S3method(to_basic,GeomArea)
@@ -78,8 +69,6 @@ S3method(to_basic,GeomTile)
7869
S3method(to_basic,GeomViolin)
7970
S3method(to_basic,GeomVline)
8071
S3method(to_basic,default)
81-
S3method(transmute_,plotly)
82-
S3method(ungroup,plotly)
8372
export("%>%")
8473
export(TeX)
8574
export(add_annotations)
@@ -259,6 +248,8 @@ importFrom(lazyeval,is_formula)
259248
importFrom(lazyeval,is_lang)
260249
importFrom(magrittr,"%>%")
261250
importFrom(purrr,transpose)
251+
importFrom(rlang,"!!!")
252+
importFrom(rlang,"!!")
262253
importFrom(rlang,eval_tidy)
263254
importFrom(stats,complete.cases)
264255
importFrom(stats,is.leaf)

R/add.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ add_sf <- function(p, ..., x = ~x, y = ~y, data = NULL, inherit = TRUE) {
334334
y = y,
335335
`_bbox` = bbox,
336336
set = set,
337-
data = if ("group" %in% names(d[[i]])) group_by_(d[[i]], "group", add = TRUE) else d[[i]],
337+
data = if ("group" %in% names(d[[i]])) group_by_add(d[[i]], !!rlang::sym("group")) else d[[i]],
338338
inherit = inherit
339339
)
340340
args <- modify_list(args, attrs)

R/ggplotly.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ gg2list <- function(p, width = NULL, height = NULL,
517517
)
518518
}
519519
# anchor X axis to the lowest plot in its column
520-
layout$layout <- dplyr::group_by_(layout$layout, "xaxis")
520+
layout$layout <- dplyr::group_by(layout$layout, !!rlang::sym("xaxis"))
521521
layout$layout <- dplyr::mutate(layout$layout, xanchor = max(as.integer(yaxis)))
522522
}
523523
layout$layout <- as.data.frame(layout$layout)
@@ -1112,7 +1112,7 @@ gg2list <- function(p, width = NULL, height = NULL,
11121112
# translate group aesthetics to data attributes
11131113
return_dat <- Map(function(x, y) {
11141114
if (is.null(y[["group"]])) return(x)
1115-
dplyr::group_by_(x, y[["group"]])
1115+
dplyr::group_by(x, !!rlang::as_quosure(y[["group"]]))
11161116
}, return_dat, mappingFormulas)
11171117

11181118
# don't need to add group as an attribute anymore

R/imports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#' @importFrom purrr transpose
1515
#' @importFrom tools file_ext file_path_sans_ext
1616
#' @importFrom data.table as.data.table setorderv
17-
#' @importFrom rlang eval_tidy
17+
#' @importFrom rlang eval_tidy !! !!!
1818
NULL
1919

2020

R/onLoad.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.onLoad <- function(...) {
2+
# These generics are defined in R/plotly_data.R
3+
dplyr_generics <- c(
4+
"groups", "ungroup", "group_by", "summarise", "mutate", "do", "arrange",
5+
"select", "filter", "distinct", "slice", "rename", "transmute"
6+
)
7+
dplyr_generics <- paste0("dplyr::", dplyr_generics)
8+
for (generic in dplyr_generics) {
9+
vctrs::s3_register(generic, "plotly")
10+
if (generic %in% c("dplyr::groups", "dplyr::ungroup")) {
11+
next
12+
}
13+
vctrs::s3_register(paste0(generic, "_"), "plotly")
14+
}
15+
}

R/plotly_build.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ train_data <- function(data, trace) {
561561
idx2 <- seq.int(2, NROW(dat), by = 2)
562562
dat[idx2, "x"] <- data[["xend"]]
563563
dat[idx2, "y"] <- data[["yend"]]
564-
data <- dplyr::group_by_(dat, ".plotlyGroupIndex", add = TRUE)
564+
data <- group_by_add(dat, !!rlang::sym(".plotlyGroupIndex"))
565565
}
566566

567567
# TODO: a lot more geoms!!!

0 commit comments

Comments
 (0)