Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
compatible with dplyr v0.8.0 (dev)
  • Loading branch information
earowang committed Jan 14, 2019
1 parent c0a952a commit 02b9010
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion R/as-tsibble.R
Expand Up @@ -498,7 +498,7 @@ duplicated_key_index <- function(data, key, index) {
# time zone associated with the index will be dropped,
# e.g. nycflights13::weather, thus result in duplicates.
# dup <- anyDuplicated(data[, identifiers, drop = FALSE])
res <- grouped_df(data, vars = key) %>%
res <- grouped_df(as_tibble(data), key) %>%
summarise(!! "zzz" := anyDuplicated.default(!! index)) %>%
dplyr::pull(!! "zzz")
any_not_equal_to_c(res, 0)
Expand Down
5 changes: 2 additions & 3 deletions R/index-by.R
Expand Up @@ -78,11 +78,10 @@ index_by.tbl_ts <- function(.data, ...) {
if (identical(idx_chr, expr_name)) {
abort(sprintf("Column `%s` (index) can't be overwritten.", idx_chr))
}
idx2 <- sym(expr_name)
# ungroup() protect the index class
tbl <- mutate(ungroup(.data), !!! exprs) %>%
group_by(!!! groups(.data)) %>%
new_tsibble_class("grouped_ts")
idx2 <- sym(expr_name)
group_by(!!! groups(.data), !! idx2)
build_tsibble(
tbl, key = key(.data), index = !! idx, index2 = !! idx2,
regular = is_regular(.data), validate = FALSE,
Expand Down
7 changes: 4 additions & 3 deletions R/key-group.R
Expand Up @@ -56,11 +56,12 @@ key_by.tbl_ts <- function(.data, ...) {
exprs <- enexprs(...)
key <- validate_key(.data, exprs)
validate <- !all(is.element(key(.data), key))
idx <- index(.data)
if (validate) {
.data <- retain_tsibble(.data, key, index(.data))
.data <- retain_tsibble(.data, key, idx)
}
build_tsibble_meta(
.data, key = key, index = !! index(.data), index2 = !! index2(.data),
.data, key = key, index = !! idx, index2 = !! index2(.data),
regular = is_regular(.data), ordered = is_ordered(.data),
interval = interval(.data)
)
Expand Down Expand Up @@ -118,7 +119,7 @@ key_indices <- function(x) {
#' @export
key_indices.tbl_ts <- function(x) {
key_vars <- key_vars(x)
grped_key <- grouped_df(x, key_vars)
grped_key <- grouped_df(as_tibble(x), key_vars)
group_indices(grped_key)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-tsibble.R
Expand Up @@ -64,7 +64,7 @@ test_that("nanotime with 1 nanoseconds interval", {

test_that("POSIXt with 1 second interval", {
expect_identical(index_valid(dat_x$date_time), TRUE)
expect_message(tsbl <- as_tsibble(dat_x))
expect_message(tsbl <- as_tsibble(dat_x), "Using `date_time` as index variable.")
expect_output(print(tsbl), "A tsibble: 5 x 2 \\[1s\\]")
expect_error(as_tsibble(dat_x, key = id(date_time)))
expect_is(tsbl, "tbl_ts")
Expand Down

0 comments on commit 02b9010

Please sign in to comment.