Skip to content

Commit 983b227

Browse files
committed
Rename functions
1 parent 11e8ad0 commit 983b227

10 files changed

+96
-129
lines changed

NAMESPACE

+2-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ S3method(plot,tbl_regression)
6262
S3method(plot,tbl_uvregression)
6363
S3method(print,gtsummary)
6464
S3method(print,tbl_split)
65-
S3method(tbl_filter,tbl_hierarchical)
6665
S3method(tbl_regression,brmsfit)
6766
S3method(tbl_regression,crr)
6867
S3method(tbl_regression,default)
@@ -78,7 +77,6 @@ S3method(tbl_regression,multinom)
7877
S3method(tbl_regression,stanreg)
7978
S3method(tbl_regression,survreg)
8079
S3method(tbl_regression,workflow)
81-
S3method(tbl_sort,tbl_hierarchical)
8280
S3method(tbl_split,gtsummary)
8381
S3method(tbl_survfit,data.frame)
8482
S3method(tbl_survfit,list)
@@ -141,6 +139,7 @@ export(contains)
141139
export(continuous_summary)
142140
export(ends_with)
143141
export(everything)
142+
export(filter_hierarchical)
144143
export(filter_p)
145144
export(gather_ard)
146145
export(get_gtsummary_theme)
@@ -209,6 +208,7 @@ export(select)
209208
export(separate_p_footnotes)
210209
export(set_gtsummary_theme)
211210
export(show_header_names)
211+
export(sort_hierarchical)
212212
export(sort_p)
213213
export(starts_with)
214214
export(style_number)
@@ -224,13 +224,11 @@ export(tbl_butcher)
224224
export(tbl_continuous)
225225
export(tbl_cross)
226226
export(tbl_custom_summary)
227-
export(tbl_filter)
228227
export(tbl_hierarchical)
229228
export(tbl_hierarchical_count)
230229
export(tbl_likert)
231230
export(tbl_merge)
232231
export(tbl_regression)
233-
export(tbl_sort)
234232
export(tbl_split)
235233
export(tbl_stack)
236234
export(tbl_strata)

R/tbl_filter.R renamed to R/filter_hierarchical.R

+8-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#' @param keep_empty (scalar `logical`)\cr
1212
#' Logical argument indicating whether to retain summary rows corresponding to table hierarchy sections that have had
1313
#' all rows filtered out. Default is `FALSE`.
14-
#' @inheritParams rlang::args_dots_empty
1514
#'
1615
#' @details
1716
#' The `filter` argument can be used to filter out rows of a table which do not meet the criteria provided as an
@@ -35,8 +34,9 @@
3534
#'
3635
#' @return A `gtsummary` of the same class as `x`.
3736
#'
38-
#' @name tbl_filter
39-
#' @seealso [tbl_sort()]
37+
#' @seealso [sort_hierarchical()]
38+
#'
39+
#' @export
4040
#'
4141
#' @examplesIf (identical(Sys.getenv("NOT_CRAN"), "true") || identical(Sys.getenv("IN_PKGDOWN"), "true"))
4242
#' ADAE_subset <- cards::ADAE |>
@@ -55,26 +55,17 @@
5555
#' )
5656
#'
5757
#' # Example 1 - Row Sums > 3 -------------------
58-
#' tbl_filter(tbl, sum(n) > 3)
58+
#' filter_hierarchical(tbl, sum(n) > 3)
5959
#'
6060
#' # Example 2 - Row Sums <= 3 ------------------
61-
#' tbl_filter(tbl, sum(n) <= 3)
62-
NULL
61+
#' filter_hierarchical(tbl, sum(n) <= 3)
62+
filter_hierarchical <- function(x, filter, keep_empty = FALSE) {
63+
set_cli_abort_call()
6364

64-
#' @rdname tbl_filter
65-
#' @export
66-
tbl_filter <- function(x, ...) {
65+
# check input
6766
check_not_missing(x)
6867
check_class(x, "gtsummary")
6968

70-
UseMethod("tbl_filter")
71-
}
72-
73-
#' @export
74-
#' @rdname tbl_filter
75-
tbl_filter.tbl_hierarchical <- function(x, filter, keep_empty = FALSE, ...) {
76-
set_cli_abort_call()
77-
7869
ard_args <- attributes(x$cards$tbl_hierarchical)$args
7970
x_ard <- x$cards$tbl_hierarchical
8071

R/tbl_sort.R renamed to R/sort_hierarchical.R

+8-17
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
#' all variables, an error will occur.
2222
#'
2323
#' Defaults to `"descending"`.
24-
#' @inheritParams rlang::args_dots_empty
2524
#'
2625
#' @return A `gtsummary` of the same class as `x`.
2726
#'
28-
#' @name tbl_sort
29-
#' @seealso [tbl_filter()]
27+
#' @seealso [filter_hierarchical()]
28+
#'
29+
#' @export
3030
#'
3131
#' @examplesIf (identical(Sys.getenv("NOT_CRAN"), "true") || identical(Sys.getenv("IN_PKGDOWN"), "true"))
3232
#' theme_gtsummary_compact()
@@ -48,28 +48,19 @@
4848
#'
4949
#'
5050
#' # Example 1 - Descending Frequency Sort ------------------
51-
#' tbl_sort(tbl)
51+
#' sort_hierarchical(tbl)
5252
#'
5353
#' # Example 2 - Alphanumeric Sort --------------------------
54-
#' tbl_sort(tbl, sort = "alphanumeric")
54+
#' sort_hierarchical(tbl, sort = "alphanumeric")
5555
#'
5656
#' reset_gtsummary_theme()
57-
NULL
57+
sort_hierarchical <- function(x, sort = c("descending", "alphanumeric")) {
58+
set_cli_abort_call()
5859

59-
#' @rdname tbl_sort
60-
#' @export
61-
tbl_sort <- function(x, ...) {
60+
# check input
6261
check_not_missing(x)
6362
check_class(x, "gtsummary")
6463

65-
UseMethod("tbl_sort")
66-
}
67-
68-
#' @rdname tbl_sort
69-
#' @export
70-
tbl_sort.tbl_hierarchical <- function(x, sort = c("descending", "alphanumeric"), ...) {
71-
set_cli_abort_call()
72-
7364
sort <- arg_match(sort, error_call = get_cli_abort_call())
7465
ard_args <- attributes(x$cards$tbl_hierarchical)$args
7566
x_ard <- x$cards$tbl_hierarchical

man/tbl_filter.Rd renamed to man/filter_hierarchical.Rd

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

man/tbl_sort.Rd renamed to man/sort_hierarchical.Rd

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

pkgdown/_pkgdown.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ reference:
8383
- subtitle: Hierarchical Summary Tables
8484
- contents:
8585
- tbl_hierarchical
86-
- tbl_sort.tbl_hierarchical
87-
- tbl_filter.tbl_hierarchical
86+
- sort_hierarchical
87+
- filter_hierarchical
8888
- add_overall.tbl_hierarchical
8989
- subtitle: Likert Summary Tables
9090
- contents:

tests/testthat/_snaps/tbl_filter.md renamed to tests/testthat/_snaps/filter_hierarchical.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# tbl_filter.tbl_hierarchical() works
1+
# filter_hierarchical() works
22

33
Code
44
as.data.frame(tbl)
@@ -17,7 +17,7 @@
1717
11 DIARRHOEA 6 (20%) 3 (7.5%) 2 (5.9%)
1818
12 ERYTHEMA 3 (10%) 5 (13%) 6 (18%)
1919

20-
# tbl_filter.tbl_hierarchical() works with various different filter conditions
20+
# filter_hierarchical() works with various different filter conditions
2121

2222
Code
2323
as.data.frame(tbl_f)
@@ -36,19 +36,19 @@
3636
11 DIARRHOEA 6 (20%) 3 (7.5%) 2 (5.9%)
3737
12 ERYTHEMA 3 (10%) 5 (13%) 6 (18%)
3838

39-
# tbl_filter.tbl_hierarchical() error messaging works
39+
# filter_hierarchical() error messaging works
4040

4141
Code
42-
tbl_filter(data.frame(), sum(n) > 10)
42+
filter_hierarchical(data.frame(), sum(n) > 10)
4343
Condition
44-
Error in `check_class()`:
44+
Error in `filter_hierarchical()`:
4545
! The `x` argument must be class <gtsummary>, not a data frame.
4646

4747
---
4848

4949
Code
50-
tbl_filter(tbl, 10)
50+
filter_hierarchical(tbl, 10)
5151
Condition
52-
Error in `tbl_filter()`:
52+
Error in `filter_hierarchical()`:
5353
! The `filter` argument must be an expression.
5454

tests/testthat/_snaps/tbl_sort.md renamed to tests/testthat/_snaps/sort_hierarchical.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# tbl_sort.tbl_hierarchical() works
1+
# sort_hierarchical() works
22

33
Code
44
as.data.frame(tbl)
@@ -30,19 +30,19 @@
3030
24 AMERICAN INDIAN OR ALASKA NATIVE 0 (NA%) 1 (100%) 0 (NA%)
3131
25 ERYTHEMA 0 (NA%) 1 (100%) 0 (NA%)
3232

33-
# tbl_sort.tbl_hierarchical() error messaging works
33+
# sort_hierarchical() error messaging works
3434

3535
Code
36-
tbl_sort(data.frame())
36+
sort_hierarchical(data.frame())
3737
Condition
38-
Error in `check_class()`:
38+
Error in `sort_hierarchical()`:
3939
! The `x` argument must be class <gtsummary>, not a data frame.
4040

4141
---
4242

4343
Code
44-
tbl_sort(tbl, "10")
44+
sort_hierarchical(tbl, "10")
4545
Condition
46-
Error in `tbl_sort()`:
46+
Error in `sort_hierarchical()`:
4747
! `sort` must be one of "descending" or "alphanumeric", not "10".
4848

0 commit comments

Comments
 (0)