Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions R/gaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ scan_gaps.tbl_ts <- function(.data, .full = FALSE, .start = NULL, .end = NULL) {
"Argument `.start` can only take a value earlier than %s.", start))
}
keyed_lst <- summarise(keyed_tbl,
!!idx_chr := list2(!!idx_chr := seq_generator(c(.start, max(!!idx)), int)))
!!idx_chr := list2(!!idx_chr := seq_generator(c(.start, max(!!idx)), .env$int)))
keyed_tbl <- group_by(unwrap(keyed_lst, !!idx), !!!key)
}
if (is_end) {
Expand All @@ -151,7 +151,7 @@ scan_gaps.tbl_ts <- function(.data, .full = FALSE, .start = NULL, .end = NULL) {
"Argument `.end` can only take a value later than %s.", end))
}
keyed_lst <- summarise(keyed_tbl,
!!idx_chr := list2(!!idx_chr := seq_generator(c(min(!!idx), .end), int)))
!!idx_chr := list2(!!idx_chr := seq_generator(c(min(!!idx), .end), .env$int)))
keyed_tbl <- group_by(unwrap(keyed_lst, !!idx), !!!key)
}
if (is_start && is_end) {
Expand All @@ -163,17 +163,17 @@ scan_gaps.tbl_ts <- function(.data, .full = FALSE, .start = NULL, .end = NULL) {
summarise(keyed_tbl, !!idx_chr := list2(!!idx_chr := idx_full))
} else if (is_false(.full)) {
sum_data <- summarise(keyed_tbl,
!!idx_chr := list2(!!idx_chr := seq_generator(!!idx, int)))
!!idx_chr := list2(!!idx_chr := seq_generator(!!idx, .env$int)))
} else if (call_name(.full) == "start") {
abort_if_args_present(.full)
start <- min(keyed_tbl[[idx_chr]])
sum_data <- summarise(keyed_tbl,
!!idx_chr := list2(!!idx_chr := seq_generator(c(start, max(!!idx)), int)))
!!idx_chr := list2(!!idx_chr := seq_generator(c(start, max(!!idx)), .env$int)))
} else if (call_name(.full) == "end") {
abort_if_args_present(.full)
end <- max(keyed_tbl[[idx_chr]])
sum_data <- summarise(keyed_tbl,
!!idx_chr := list2(!!idx_chr := seq_generator(c(min(!!idx), end), int)))
!!idx_chr := list2(!!idx_chr := seq_generator(c(min(!!idx), end), .env$int)))
} else {
abort_invalid_full_arg()
}
Expand Down Expand Up @@ -277,12 +277,12 @@ has_gaps <- function(.data, .full = FALSE, .name = ".gaps",
if (lgl || quo_is_symbol(.full)) {
.full <- eval_tidy(.full)
if (is_true(.full)) {
idx_full <- seq_generator(.data[[idx_chr]], int)
idx_full <- seq_generator(.data[[idx_chr]], .env$int)
res <- summarise(grped_tbl,
!!.name := (length(idx_full) - length(!!idx)) > 0)
} else if (is_false(.full)) {
res <- summarise(grped_tbl,
!!.name := (length(seq_generator(!!idx, int)) - length(!!idx)) > 0
!!.name := (length(seq_generator(!!idx, .env$int)) - length(!!idx)) > 0
)
} else {
abort_invalid_full_arg()
Expand All @@ -292,13 +292,13 @@ has_gaps <- function(.data, .full = FALSE, .name = ".gaps",
abort_if_args_present(.full)
start <- min(.data[[idx_chr]])
res <- summarise(grped_tbl,
!!.name := (length(seq_generator(c(start, max(!!idx)), int)) - length(!!idx)) > 0
!!.name := (length(seq_generator(c(start, max(!!idx)), .env$int)) - length(!!idx)) > 0
)
} else if (call_name(.full) == "end") {
abort_if_args_present(.full)
end <- max(.data[[idx_chr]])
res <- summarise(grped_tbl,
!!.name := (length(seq_generator(c(min(!!idx), end), int)) - length(!!idx)) > 0
!!.name := (length(seq_generator(c(min(!!idx), end), .env$int)) - length(!!idx)) > 0
)
} else {
abort_invalid_full_arg()
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-gaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,13 @@ test_that("seq_generator()", {
}
expect_error(seq_generator(y, default_time_units(interval_pull(y))), "defined")
})

test_that("issue #323: scan_gaps/has_gaps with column named `int`", {
x_bug <- tsibble::tsibble(
time = 1:5,
int = 1L,
index = time
)

expect_s3_class(tsibble::scan_gaps(x_bug), "tbl_ts")
})
Loading