Skip to content

Commit 8f9d804

Browse files
Fix dplyr_row_slice method when i variable name is present
Resolves #317
1 parent 725d530 commit 8f9d804

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

R/dplyr-verbs.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# tidy evaluation pronouns
2+
globalVariables(c(".data", ".env"))
3+
14
#' Tidyverse methods for tsibble
25
#'
36
#' @description
@@ -210,7 +213,7 @@ count.tbl_ts <- function(x, ..., wt = NULL, sort = FALSE, name = NULL) {
210213
#' @export
211214
dplyr_row_slice.tbl_ts <- function(data, i, ..., preserve = FALSE) {
212215
tbl <- as_tibble(data)
213-
loc_df <- summarise(tbl, !!".loc" := list2(i))
216+
loc_df <- summarise(tbl, !!".loc" := list2(.env$i))
214217
ascending <- all(map_lgl(loc_df[[".loc"]], validate_order))
215218
res <- dplyr_row_slice(tbl, i, ..., preserve = preserve)
216219
if (preserve) {

tests/testthat/test-dplyr.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,14 @@ test_that("drop redundant key #196", {
361361
select(-Purpose)
362362
expect_equal(key_vars(sim_tourism), c("Region", "State"))
363363
})
364+
365+
test_that("filter() with `i` name in data #317", {
366+
tsibble::tsibble(
367+
i = rep(1:5, 2),
368+
k = c(rep('a', 5), rep('b', 5)),
369+
x = c(rnorm(5), rpois(5, 1)),
370+
key = k,
371+
index = i
372+
) %>%
373+
filter(k == 'a')
374+
})

0 commit comments

Comments
 (0)