174174# ' @param other_keys If your tibble has additional keys, be sure to specify them
175175# ' as a character vector here (typical examples are "age" or sub-geographies).
176176# ' @param ... Additional arguments passed to methods.
177- # ' @return An `epi_df` object.
177+ # ' @return * Of `new_epi_df()`: an `epi_df`
178178# '
179179# ' @export
180180new_epi_df <- function (x = tibble :: tibble(geo_value = character (), time_value = as.Date(integer())),
@@ -205,6 +205,8 @@ new_epi_df <- function(x = tibble::tibble(geo_value = character(), time_value =
205205# ' to be converted
206206# ' @param ... used for specifying column names, as in [`dplyr::rename`]. For
207207# ' example, `geo_value = STATEFP, time_value = end_date`.
208+ # ' @return * Of `as_epi_df()`: an (ungrouped) `epi_df`
209+ # '
208210# ' @export
209211as_epi_df <- function (x , ... ) {
210212 UseMethod(" as_epi_df" )
@@ -232,6 +234,7 @@ as_epi_df.tbl_df <- function(
232234 as_of ,
233235 other_keys = character (),
234236 ... ) {
237+ x <- ungroup(x )
235238 x <- rename(x , ... )
236239 x <- guess_column_name(x , " time_value" , time_column_names())
237240 x <- guess_column_name(x , " geo_value" , geo_column_names())
@@ -296,6 +299,14 @@ as_epi_df.tbl_df <- function(
296299 new_epi_df(x , geo_type , time_type , as_of , other_keys )
297300}
298301
302+ # ' @rdname epi_df
303+ # ' @order 1
304+ # ' @method as_epi_df grouped_df
305+ # ' @export
306+ as_epi_df.grouped_df <- function (x , ... ) {
307+ as_epi_df(ungroup(x ), ... )
308+ }
309+
299310# ' @rdname epi_df
300311# ' @order 1
301312# ' @method as_epi_df data.frame
@@ -319,9 +330,11 @@ as_epi_df.tbl_ts <- function(x, as_of, other_keys = character(), ...) {
319330# ' Test for `epi_df` format
320331# '
321332# ' @param x An object.
322- # ' @return `TRUE` if the object inherits from `epi_df`.
333+ # ' @return * Of `is_epi_df`: `TRUE` if the object inherits from `epi_df`,
334+ # ' otherwise `FALSE`.
323335# '
324336# ' @rdname epi_df
337+ # ' @order 1
325338# ' @export
326339is_epi_df <- function (x ) {
327340 inherits(x , " epi_df" )
0 commit comments