Skip to content

Commit 4290363

Browse files
committed
Add group_vars.grouped_epi_archive
1 parent 547d156 commit 4290363

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ S3method(group_by,epi_df)
2727
S3method(group_by,grouped_epi_archive)
2828
S3method(group_by_drop_default,grouped_epi_archive)
2929
S3method(group_modify,epi_df)
30+
S3method(group_vars,grouped_epi_archive)
3031
S3method(groups,grouped_epi_archive)
3132
S3method(guess_period,Date)
3233
S3method(guess_period,POSIXt)

R/archive.R

+7-2
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ print.epi_archive <- function(x, ..., class = TRUE, methods = TRUE) {
585585
#' `...`.
586586
#' @param .drop As described in [`dplyr::group_by`]; determines treatment of
587587
#' factor columns.
588-
#' @param x For `groups` or `ungroup`: a `grouped_epi_archive`; for
589-
#' `is_grouped_epi_archive`: any object
588+
#' @param x For `groups`, `group_vars`, or `ungroup`: a `grouped_epi_archive`;
589+
#' for `is_grouped_epi_archive`: any object
590590
#' @param .tbl (For `group_by_drop_default`:) an `epi_archive` or
591591
#' `grouped_epi_archive` (`epi_archive` dispatches to the S3 default method;
592592
#' `grouped_epi_archive` dispatches its own S3 method)
@@ -665,6 +665,11 @@ print.epi_archive <- function(x, ..., class = TRUE, methods = TRUE) {
665665
#' group_by(geo_value, age_group) %>%
666666
#' ungroup(age_group)
667667
#'
668+
#' # To get the grouping variable names as a character vector:
669+
#' toy_archive %>%
670+
#' group_by(geo_value) %>%
671+
#' group_vars()
672+
#'
668673
#' # To get the grouping variable names as a `list` of `name`s (a.k.a. symbols):
669674
#' toy_archive %>%
670675
#' group_by(geo_value) %>%

R/grouped_epi_archive.R

+9-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ new_grouped_epi_archive <- function(x, vars, drop) {
5555
or `ungroup` first.",
5656
class = "epiprocess__grouped_epi_archive__ungrouped_arg_is_already_grouped",
5757
epiprocess__ungrouped_class = class(x),
58-
epiprocess__ungrouped_groups = groups(x)
58+
epiprocess__ungrouped_group_vars = group_vars(x)
5959
)
6060
}
6161
assert_class(x, "epi_archive")
@@ -160,6 +160,14 @@ group_by_drop_default.grouped_epi_archive <- function(.tbl) {
160160
.tbl$private$drop
161161
}
162162

163+
#' @include methods-epi_archive.R
164+
#' @rdname group_by.epi_archive
165+
#'
166+
#' @importFrom dplyr group_vars
167+
#' @export
168+
group_vars.grouped_epi_archive <- function(x) {
169+
x$private$vars
170+
}
163171

164172
#' @include methods-epi_archive.R
165173
#' @rdname group_by.epi_archive
@@ -170,7 +178,6 @@ groups.grouped_epi_archive <- function(x) {
170178
rlang::syms(x$private$vars)
171179
}
172180

173-
174181
#' @include methods-epi_archive.R
175182
#' @rdname group_by.epi_archive
176183
#'

man/group_by.epi_archive.Rd

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-methods-epi_archive.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ test_that("epix_truncate_version_after returns the same grouping type as input e
110110
expect_true(is_grouped_epi_archive(ea_as_of))
111111
})
112112

113-
114113
test_that("epix_truncate_version_after returns the same groups as input grouped_epi_archive", {
115114
ea2 <- ea2_data %>%
116115
as_epi_archive()
@@ -122,3 +121,8 @@ test_that("epix_truncate_version_after returns the same groups as input grouped_
122121
epix_truncate_versions_after(max_version = as.Date("2020-06-04"))
123122
expect_equal(ea_as_of %>% groups(), ea_expected %>% groups())
124123
})
124+
125+
test_that("group_vars works as expected", {
126+
expect_equal(ea2_data %>% as_epi_archive() %>% group_by(geo_value) %>% group_vars(),
127+
"geo_value")
128+
})

0 commit comments

Comments
 (0)