@@ -41,10 +41,13 @@ as_tibble.epi_df <- function(x, ...) {
4141# ' @export
4242as_tsibble.epi_df <- function (x , key , ... ) {
4343 if (missing(key )) key <- c(" geo_value" , attributes(x )$ metadata $ other_keys )
44- return (as_tsibble(tibble :: as_tibble(x ),
45- key = tidyselect :: all_of(key ), index = " time_value" ,
46- ...
47- ))
44+ return (
45+ as_tsibble(
46+ tibble :: as_tibble(x ),
47+ key = tidyselect :: all_of(key ), index = " time_value" ,
48+ ...
49+ )
50+ )
4851}
4952
5053# ' Base S3 methods for an `epi_df` object
@@ -150,10 +153,10 @@ dplyr_reconstruct.epi_df <- function(data, template) {
150153 # keep any grouping that has been applied:
151154 res <- NextMethod()
152155
153- cn <- names(res )
156+ col_names <- names(res )
154157
155158 # Duplicate columns, cli_abort
156- dup_col_names <- cn [duplicated(cn )]
159+ dup_col_names <- col_names [duplicated(col_names )]
157160 if (length(dup_col_names ) != 0 ) {
158161 cli_abort(c(
159162 " Duplicate column names are not allowed" ,
@@ -163,7 +166,7 @@ dplyr_reconstruct.epi_df <- function(data, template) {
163166 ))
164167 }
165168
166- not_epi_df <- ! (" time_value" %in% cn ) || ! (" geo_value" %in% cn )
169+ not_epi_df <- ! (" time_value" %in% col_names ) || ! (" geo_value" %in% col_names )
167170
168171 if (not_epi_df ) {
169172 # If we're calling on an `epi_df` from one of our own functions, we need to
@@ -182,7 +185,7 @@ dplyr_reconstruct.epi_df <- function(data, template) {
182185
183186 # Amend additional metadata if some other_keys cols are dropped in the subset
184187 old_other_keys <- attr(template , " metadata" )$ other_keys
185- attr(res , " metadata" )$ other_keys <- old_other_keys [old_other_keys %in% cn ]
188+ attr(res , " metadata" )$ other_keys <- old_other_keys [old_other_keys %in% col_names ]
186189
187190 res
188191}
@@ -424,9 +427,13 @@ arrange_col_canonical.epi_df <- function(x, ...) {
424427 x %> % dplyr :: relocate(dplyr :: all_of(cols ), .before = 1 )
425428}
426429
430+ # ' Group an `epi_df` object by default keys
431+ # ' @param x an `epi_df`
432+ # ' @param exclude character vector of column names to exclude from grouping
433+ # ' @return a grouped `epi_df`
427434# ' @export
428- group_epi_df <- function (x ) {
429- cols <- kill_time_value( key_colnames(x ) )
435+ group_epi_df <- function (x , exclude = character () ) {
436+ cols <- key_colnames(x , exclude = exclude )
430437 x %> % group_by(across(all_of(cols )))
431438}
432439
@@ -437,7 +444,7 @@ group_epi_df <- function(x) {
437444# ' the resulting `epi_df` will have `geo_value` set to `"total"`.
438445# '
439446# ' @param .x an `epi_df`
440- # ' @param value_col character vector of the columns to aggregate
447+ # ' @param sum_cols character vector of the columns to aggregate
441448# ' @param group_cols character vector of column names to group by. "time_value" is
442449# ' included by default.
443450# ' @return an `epi_df` object
0 commit comments