174
174
# ' @param other_keys If your tibble has additional keys, be sure to specify them
175
175
# ' as a character vector here (typical examples are "age" or sub-geographies).
176
176
# ' @param ... Additional arguments passed to methods.
177
- # ' @return An `epi_df` object.
177
+ # ' @return * Of `new_epi_df()`: an `epi_df`
178
178
# '
179
179
# ' @export
180
180
new_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 =
205
205
# ' to be converted
206
206
# ' @param ... used for specifying column names, as in [`dplyr::rename`]. For
207
207
# ' example, `geo_value = STATEFP, time_value = end_date`.
208
+ # ' @return * Of `as_epi_df()`: an (ungrouped) `epi_df`
209
+ # '
208
210
# ' @export
209
211
as_epi_df <- function (x , ... ) {
210
212
UseMethod(" as_epi_df" )
@@ -215,6 +217,7 @@ as_epi_df <- function(x, ...) {
215
217
# ' @method as_epi_df epi_df
216
218
# ' @export
217
219
as_epi_df.epi_df <- function (x , ... ) {
220
+ x <- ungroup(x )
218
221
return (x )
219
222
}
220
223
@@ -296,6 +299,14 @@ as_epi_df.tbl_df <- function(
296
299
new_epi_df(x , geo_type , time_type , as_of , other_keys )
297
300
}
298
301
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
+
299
310
# ' @rdname epi_df
300
311
# ' @order 1
301
312
# ' @method as_epi_df data.frame
@@ -319,9 +330,11 @@ as_epi_df.tbl_ts <- function(x, as_of, other_keys = character(), ...) {
319
330
# ' Test for `epi_df` format
320
331
# '
321
332
# ' @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`.
323
335
# '
324
336
# ' @rdname epi_df
337
+ # ' @order 1
325
338
# ' @export
326
339
is_epi_df <- function (x ) {
327
340
inherits(x , " epi_df" )
0 commit comments