Skip to content

Commit

Permalink
Merge pull request #83 from business-science/issue-81
Browse files Browse the repository at this point in the history
Issue 81
  • Loading branch information
DavisVaughan authored Sep 20, 2019
2 parents 3cb1607 + 2195e29 commit 9c0dcc8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# tibbletime (development version)

* Bug fixes

* `collapse_by()` no longer errors when there is a column
named `start_date` in the `tbl_time` object (#81).

## tibbletime 0.1.2

* Features
Expand Down
4 changes: 3 additions & 1 deletion R/collapse_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,14 @@ collapse_by <- function(.tbl_time, period = "yearly", start_date = NULL, side =
index_quo <- get_index_quo(.tbl_time)
index_char <- get_index_char(.tbl_time)

start_date <- rlang::enquo(start_date)

.tbl_time_collapsed <- dplyr::mutate(
.data = .tbl_time,
!! index_char := collapse_index(
index = !! index_quo,
period = period,
start_date = start_date,
start_date = !! start_date,
side = side,
clean = clean,
...
Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/test_collapse_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,29 @@ test_that("day becomes DSTday for POSIXct to prevent DST boundary problems", {

expect_equal(ret, test)
})

test_that("can use `collapse_by()` when a column is named `start_date` (#81)", {
x <- data.frame(
start_date = as.Date("2017-12-01") + 0:2,
value = c(1, 2, 3)
)

x <- as_tbl_time(x, start_date)

expect_equal(
collapse_by(x),
dplyr::mutate(x, start_date = collapse_index(start_date))
)

expect_equal(
collapse_by(x, start_date = as.Date("2017-01-01"), side = "start", period = "2 days"),
dplyr::mutate(x, start_date = collapse_index(start_date, "2 days", start_date = as.Date("2017-01-01"), side = "start"))
)

expect_equal(
collapse_by(x, start_date = as.Date("2016-12-31"), side = "start", period = "2 days"),
dplyr::mutate(x, start_date = collapse_index(start_date, "2 days", start_date = as.Date("2016-12-31"), side = "start"))
)
})


0 comments on commit 9c0dcc8

Please sign in to comment.