Skip to content

Commit e4435d6

Browse files
committed
Prefer vec_slice() over [,, drop = FALSE]
1 parent 9a329c3 commit e4435d6

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

R/compat-dplyr.R

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ lead <- function(x, n = 1L, default = NA) {
1313

1414
arrange <- function(.data, ...) {
1515
ord <- eval(substitute(order(...)), .data, parent.frame())
16-
.data[ord, , drop = FALSE]
16+
vec_slice(.data, ord)
1717
}
1818

1919
arrange_pos_id <- function(data) {
2020
pos_id <- data$pos_id
2121
if (is.unsorted(pos_id)) {
22-
data <- data[order(pos_id), , drop = FALSE]
22+
data <- vec_slice(data, order(pos_id))
2323
}
2424
data
2525
}
@@ -52,10 +52,6 @@ last <- function(x) {
5252
x[[length(x)]]
5353
}
5454

55-
slice <- function(.data, ...) {
56-
.data[c(...), , drop = FALSE]
57-
}
58-
5955
map_dfr <- function(.x, .f, ...) {
6056
.f <- purrr::as_mapper(.f, ...)
6157
res <- map(.x, .f, ...)

R/relevel.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ flatten_pd <- function(pd_nested, token, child_token = token, left = TRUE) {
8585
#' @keywords internal
8686
bind_with_child <- function(pd_nested, pos) {
8787
pd_nested %>%
88-
slice(-pos) %>%
88+
vec_slice(-pos) %>%
8989
vec_rbind(pd_nested$child[[pos]]) %>%
9090
arrange_pos_id()
9191
}

R/rules-tokens.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ wrap_subexpr_in_curly <- function(pd,
166166
remove_attributes(c("token_before", "token_after"))
167167

168168
pd %>%
169-
slice(-ind_to_be_wrapped) %>%
169+
vec_slice(-ind_to_be_wrapped) %>%
170170
vec_rbind(new_expr_in_expr) %>%
171171
set_multi_line() %>%
172172
arrange_pos_id()

0 commit comments

Comments
 (0)