Skip to content

Commit

Permalink
register S3 methods via roxygen
Browse files Browse the repository at this point in the history
  • Loading branch information
earowang committed Apr 17, 2019
1 parent be30f79 commit 8e46fd9
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 56 deletions.
45 changes: 45 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ S3method("[",yearquarter)
S3method("[",yearweek)
S3method("[[",interval)
S3method("[[",tbl_ts)
S3method(anti_join,lst_ts)
S3method(anti_join,tbl_ts)
S3method(append_row,data.frame)
S3method(append_row,tbl_ts)
S3method(arrange,grouped_ts)
S3method(arrange,lst_ts)
S3method(arrange,tbl_ts)
S3method(as.Date,yearmonth)
S3method(as.Date,yearquarter)
S3method(as.Date,yearweek)
Expand Down Expand Up @@ -48,12 +53,17 @@ S3method(diff,yearquarter)
S3method(diff,yearweek)
S3method(fill_gaps,data.frame)
S3method(fill_gaps,tbl_ts)
S3method(filter,lst_ts)
S3method(format,interval)
S3method(format,tbl_ts)
S3method(format,yearmonth)
S3method(format,yearquarter)
S3method(format,yearweek)
S3method(frequency,tbl_ts)
S3method(full_join,lst_ts)
S3method(full_join,tbl_ts)
S3method(group_by,lst_ts)
S3method(group_by,tbl_ts)
S3method(guess_frequency,Date)
S3method(guess_frequency,POSIXt)
S3method(guess_frequency,numeric)
Expand All @@ -77,6 +87,8 @@ S3method(index_valid,yearmonth)
S3method(index_valid,yearqtr)
S3method(index_valid,yearquarter)
S3method(index_valid,yearweek)
S3method(inner_join,lst_ts)
S3method(inner_join,tbl_ts)
S3method(interval_pull,Date)
S3method(interval_pull,POSIXt)
S3method(interval_pull,default)
Expand All @@ -96,21 +108,38 @@ S3method(key_data,tbl_ts)
S3method(key_drop_default,default)
S3method(key_drop_default,tbl_ts)
S3method(key_vars,tbl_ts)
S3method(left_join,lst_ts)
S3method(left_join,tbl_ts)
S3method(measured_vars,tbl_ts)
S3method(measures,tbl_ts)
S3method(mutate,lst_ts)
S3method(mutate,tbl_ts)
S3method(new_data,tbl_ts)
S3method(print,interval)
S3method(print,yearmonth)
S3method(print,yearquarter)
S3method(print,yearweek)
S3method(rbind,tbl_ts)
S3method(rename,grouped_ts)
S3method(rename,lst_ts)
S3method(rename,tbl_ts)
S3method(rep,yearmonth)
S3method(rep,yearquarter)
S3method(rep,yearweek)
S3method(right_join,lst_ts)
S3method(right_join,tbl_ts)
S3method(scan_gaps,tbl_ts)
S3method(select,grouped_ts)
S3method(select,lst_ts)
S3method(select,tbl_ts)
S3method(semi_join,lst_ts)
S3method(semi_join,tbl_ts)
S3method(seq,yearmonth)
S3method(seq,yearquarter)
S3method(seq,yearweek)
S3method(slice,lst_ts)
S3method(slice,tbl_ts)
S3method(summarise,tbl_ts)
S3method(tbl_sum,grouped_ts)
S3method(tbl_sum,tbl_ts)
S3method(time,Date)
Expand All @@ -119,10 +148,15 @@ S3method(time,numeric)
S3method(time,yearmonth)
S3method(time,yearquarter)
S3method(time,yearweek)
S3method(transmute,grouped_ts)
S3method(transmute,lst_ts)
S3method(transmute,tbl_ts)
S3method(type_sum,tbl_ts)
S3method(type_sum,yearmonth)
S3method(type_sum,yearquarter)
S3method(type_sum,yearweek)
S3method(ungroup,grouped_ts)
S3method(ungroup,tbl_ts)
S3method(unique,yearmonth)
S3method(unique,yearquarter)
S3method(unique,yearweek)
Expand Down Expand Up @@ -167,9 +201,12 @@ export(build_tsibble)
export(count_gaps)
export(difference)
export(duplicates)
export(fill.grouped_ts)
export(fill.tbl_ts)
export(fill_gaps)
export(fill_na)
export(filter_index)
export(gather.tbl_ts)
export(group_by_key)
export(guess_frequency)
export(has_gaps)
Expand Down Expand Up @@ -199,6 +236,7 @@ export(key_vars)
export(measured_vars)
export(measures)
export(n_keys)
export(nest.tbl_ts)
export(new_data)
export(new_interval)
export(new_tsibble)
Expand Down Expand Up @@ -226,6 +264,7 @@ export(slide_dfc)
export(slide_dfr)
export(slide_tsibble)
export(slider)
export(spread.tbl_ts)
export(stretch)
export(stretch2)
export(stretch2_dfc)
Expand All @@ -249,6 +288,8 @@ export(time_unit)
export(tsibble)
export(type_sum)
export(units_since)
export(unnest.lst_ts)
export(unnest.tbl_ts)
export(update_tsibble)
export(yearmonth)
export(yearquarter)
Expand All @@ -270,16 +311,20 @@ importFrom(dplyr,"%>%")
importFrom(dplyr,anti_join)
importFrom(dplyr,arrange)
importFrom(dplyr,filter)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
importFrom(dplyr,group_data)
importFrom(dplyr,group_rows)
importFrom(dplyr,group_vars)
importFrom(dplyr,grouped_df)
importFrom(dplyr,groups)
importFrom(dplyr,inner_join)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,rename)
importFrom(dplyr,right_join)
importFrom(dplyr,select)
importFrom(dplyr,semi_join)
importFrom(dplyr,slice)
importFrom(dplyr,summarise)
importFrom(dplyr,transmute)
Expand Down
6 changes: 6 additions & 0 deletions R/dplyr-join.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rename_join_tsibble <- function(x, y, by = NULL, suffix = c(".x", ".y")) {
#' @inheritParams dplyr::left_join
#' @rdname tsibble-tidyverse
#' @include dplyr-verbs.R
#' @export
left_join.tbl_ts <- function(
x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...
) {
Expand All @@ -26,6 +27,7 @@ left_join.tbl_ts <- function(
}

#' @rdname tsibble-tidyverse
#' @export
right_join.tbl_ts <- function(
x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...
) {
Expand All @@ -35,6 +37,7 @@ right_join.tbl_ts <- function(
}

#' @rdname tsibble-tidyverse
#' @export
inner_join.tbl_ts <- function(
x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...
) {
Expand All @@ -44,6 +47,7 @@ inner_join.tbl_ts <- function(
}

#' @rdname tsibble-tidyverse
#' @export
full_join.tbl_ts <- function(
x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...
) {
Expand All @@ -53,12 +57,14 @@ full_join.tbl_ts <- function(
}

#' @rdname tsibble-tidyverse
#' @export
semi_join.tbl_ts <- function(x, y, by = NULL, copy = FALSE, ...) {
tbl <- NextMethod()
update_meta(tbl, x, ordered = is_ordered(x), validate = FALSE)
}

#' @rdname tsibble-tidyverse
#' @export
anti_join.tbl_ts <- function(x, y, by = NULL, copy = FALSE, ...) {
tbl <- NextMethod()
update_meta(tbl, x, ordered = is_ordered(x), validate = FALSE)
Expand Down
20 changes: 17 additions & 3 deletions R/dplyr-verbs.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#'
#' @name tsibble-tidyverse
#' @rdname tsibble-tidyverse
#' @export
arrange.tbl_ts <- function(.data, ...) {
exprs <- enquos(...)
if (is_empty(exprs)) return(.data)
Expand All @@ -31,6 +32,7 @@ arrange.tbl_ts <- function(.data, ...) {
update_meta(arr_data, .data, ordered = ordered, interval = interval(.data))
}

#' @export
arrange.grouped_ts <- function(.data, ..., .by_group = FALSE) {
exprs <- enquos(...)
if (is_empty(exprs)) return(.data)
Expand Down Expand Up @@ -78,6 +80,7 @@ filter.tbl_ts <- function(.data, ..., .preserve = FALSE) {
}

#' @rdname tsibble-tidyverse
#' @export
slice.tbl_ts <- function(.data, ..., .preserve = FALSE) {
pos <- enquos(...)
if (length(pos) > 1) {
Expand All @@ -99,6 +102,7 @@ row_validate <- function(x) {
}

#' @rdname tsibble-tidyverse
#' @export
select.tbl_ts <- function(.data, ...) {
lst_quos <- enquos(...)
lst_exprs <- map(lst_quos, quo_get_expr)
Expand All @@ -118,16 +122,20 @@ select.tbl_ts <- function(.data, ...) {
select_tsibble(.data, !!! lst_quos)
}

#' @export
select.grouped_ts <- select.tbl_ts

#' @rdname tsibble-tidyverse
#' @export
rename.tbl_ts <- function(.data, ...) {
rename_tsibble(.data, ...)
}

#' @export
rename.grouped_ts <- rename.tbl_ts

#' @rdname tsibble-tidyverse
#' @export
mutate.tbl_ts <- function(.data, ...) {
# mutate returns lst_ts without attributes, coerce to tbl_df first
mut_data <- mutate(as_tibble(.data), ...)
Expand Down Expand Up @@ -169,6 +177,7 @@ mutate.tbl_ts <- function(.data, ...) {
}

#' @rdname tsibble-tidyverse
#' @export
transmute.tbl_ts <- function(.data, ...) {
lst_quos <- enquos(..., .named = TRUE)
mut_data <- mutate(.data, !!! lst_quos)
Expand All @@ -177,6 +186,7 @@ transmute.tbl_ts <- function(.data, ...) {
select_tsibble(mut_data, !!! vec_names, validate = FALSE)
}

#' @export
transmute.grouped_ts <- function(.data, ...) {
res <- NextMethod()
# keeping index and key
Expand All @@ -195,8 +205,9 @@ transmute.grouped_ts <- function(.data, ...) {
#' pedestrian %>%
#' as_tibble() %>%
#' summarise(Total = sum(Count))
#' @export
summarise.tbl_ts <- function(.data, ...) {
# Unlike summarise.grouped_df(), summarise.tbl_ts() doesn't compute values for
# Unlike summarise.grouped_df(), summarise.tbl_ts() doesn't compute values for
# empty groups. Bc information is unavailable over the time range for empty
# groups.
idx <- index(.data)
Expand All @@ -213,7 +224,7 @@ summarise.tbl_ts <- function(.data, ...) {
grped_data <- group_by_index2(.data)
grps <- groups(grped_data)
len_grps <- length(grps)
sum_data <-
sum_data <-
group_by(
summarise(grped_data, !!! nonkey_quos),
!!! grps[-((len_grps - 1):len_grps)] # remove index2 and last grp
Expand All @@ -226,13 +237,14 @@ summarise.tbl_ts <- function(.data, ...) {
grps <- setdiff(group_vars(.data), as_string(idx2))

build_tsibble(
sum_data, key = !! grps, index = !! idx2, regular = reg, ordered = TRUE,
sum_data, key = !! grps, index = !! idx2, regular = reg, ordered = TRUE,
interval = NULL, validate = FALSE
)
}

#' @inheritParams dplyr::group_by
#' @rdname tsibble-tidyverse
#' @export
group_by.tbl_ts <- function(.data, ..., add = FALSE,
.drop = group_by_drop_default(.data)) {
lst_quos <- enquos(..., .named = TRUE)
Expand Down Expand Up @@ -293,6 +305,7 @@ group_by_key <- function(.data, ..., .drop = key_drop_default(.data)) {
}

#' @rdname tsibble-tidyverse
#' @export
ungroup.grouped_ts <- function(x, ...) {
tbl <- ungroup(as_tibble(x))
build_tsibble_meta(
Expand All @@ -301,6 +314,7 @@ ungroup.grouped_ts <- function(x, ...) {
)
}

#' @export
ungroup.tbl_ts <- function(x, ...) {
attr(x, "index2") <- index(x)
x
Expand Down
Loading

0 comments on commit 8e46fd9

Please # to comment.