Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.0 add_nevent.tbl uvregression() #1713

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ S3method(add_n,tbl_regression)
S3method(add_n,tbl_summary)
S3method(add_n,tbl_uvregression)
S3method(add_nevent,tbl_regression)
S3method(add_nevent,tbl_uvregression)
S3method(add_overall,tbl_continuous)
S3method(add_overall,tbl_custom_summary)
S3method(add_overall,tbl_summary)
Expand Down
25 changes: 12 additions & 13 deletions R/add_n.tbl_regression.R → R/add_n_regression.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Add N to regression table
#'
#' @param x (`tbl_regression`/`tbl_uvregression`)\cr
#' @param x (`tbl_regression`, `tbl_uvregression`)\cr
#' a `tbl_regression` or `tbl_uvregression` table
#' @param location (`character`)\cr
#' location to place Ns. Select one or more of `c('label', 'level')`.
Expand All @@ -14,18 +14,17 @@
#'
#' @name add_n_regression
#' @examples
#' # TODO: Re-add after tbl_uvregression() is added
#' # # Example 1 ----------------------------------
#' # add_n.tbl_regression_ex1 <-
#' # trial %>%
#' # select(response, age, grade) %>%
#' # tbl_uvregression(
#' # y = response,
#' # method = glm,
#' # method.args = list(family = binomial),
#' # hide_n = TRUE
#' # ) %>%
#' # add_n(location = "label")
#' # Example 1 ----------------------------------
#' trial |>
#' select(response, age, grade) |>
#' tbl_uvregression(
#' y = response,
#' exponentiate = TRUE,
#' method = glm,
#' method.args = list(family = binomial),
#' hide_n = TRUE
#' ) |>
#' add_n(location = "label")
#'
#' # Example 2 ----------------------------------
#' glm(response ~ age + grade, trial, family = binomial) |>
Expand Down
52 changes: 22 additions & 30 deletions R/add_nevent.R
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
#' Add p-values
#'
#' - [`add_nevent.tbl_regression()`]
#'
#' @param x (`gtsummary`)\cr
#' Object with class 'gtsummary'
#' @param ... Passed to other methods.
#' @keywords internal
#' @author Daniel D. Sjoberg
#' @export
#'
#' @seealso [`add_p.tbl_summary()`]
add_nevent <- function(x, ...) {
check_not_missing(x)
check_class(x, "gtsummary")
UseMethod("add_nevent")
}


#' Add event N
#'
#' @inheritParams add_n_regression
#' @name add_nevent_regression
#'
#' @examples
#' # TODO: Re-add after tbl_uvregression() is migrated
#' @examplesIf gtsummary:::is_pkg_installed("broom.helpers", reference_pkg = "gtsummary")
#' # Example 1 ----------------------------------
#' # add_nevent.tbl_regression_ex1 <-
#' # trial %>%
#' # select(response, trt, grade) %>%
#' # tbl_uvregression(
#' # y = response,
#' # method = glm,
#' # method.args = list(family = binomial),
#' # ) %>%
#' # add_nevent()
#' trial |>
#' select(response, trt, grade) |>
#' tbl_uvregression(
#' y = response,
#' exponentiate = TRUE,
#' method = glm,
#' method.args = list(family = binomial),
#' ) |>
#' add_nevent()
#'
#' # Example 2 ----------------------------------
#' glm(response ~ age + grade, trial, family = binomial) |>
#' tbl_regression(exponentiate = TRUE) |>
#' add_nevent(location = "level")
NULL

#' @rdname add_nevent_regression
#' @export
add_nevent <- function(x, ...) {
check_not_missing(x)
check_class(x, "gtsummary")
UseMethod("add_nevent")
}

#' @rdname add_nevent_regression
#' @export
add_nevent.tbl_regression <- function(x, location = "label", ...) {
Expand Down Expand Up @@ -105,6 +93,10 @@ add_nevent.tbl_regression <- function(x, location = "label", ...) {
x
}

#' @rdname add_nevent_regression
#' @export
add_nevent.tbl_uvregression <- add_nevent.tbl_regression

# this function is used to fill in missing values in the
# x$table_styling$header$modify_stat_* columns
.fill_table_header_modify_stats <- function(x,
Expand Down
27 changes: 13 additions & 14 deletions man/add_n_regression.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions man/add_nevent.Rd

This file was deleted.

33 changes: 20 additions & 13 deletions man/add_nevent_regression.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ reference:
- tbl_uvregression
- add_global_p
- add_n_regression
- add_nevent.tbl_regression
- add_nevent_regression
- combine_terms
# - add_glance
- add_q
Expand Down
Loading