-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
add_total_n.survey.design.R
33 lines (31 loc) · 1.02 KB
/
add_total_n.survey.design.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#' ARD Total N
#'
#' Returns the total N for a survey object.
#' The placeholder variable name returned in the object is `"..ard_total_n.."`
#'
#' @inheritParams ard_dichotomous.survey.design
#' @inheritParams rlang::args_dots_empty
#'
#' @return an ARD data frame of class 'card'
#' @export
#'
#' @examplesIf cardx:::is_pkg_installed("survey")
#' svy_titanic <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq)
#'
#' ard_total_n(svy_titanic)
ard_total_n.survey.design <- function(data, ...) {
# process inputs -------------------------------------------------------------
set_cli_abort_call()
check_dots_empty()
# calculate total N ----------------------------------------------------------
data$variables <-
data$variables |>
dplyr::mutate(..ard_total_n.. = TRUE)
data |>
ard_dichotomous(
variables = "..ard_total_n..",
statistic = list(..ard_total_n.. = c("N", "N_unweighted"))
) |>
dplyr::mutate(context = "total_n") |>
dplyr::select(-cards::all_ard_variables("levels"))
}