Skip to content

Commit

Permalink
comply with S3 generic
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jun 22, 2024
1 parent 0b859a8 commit 953adc3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
21 changes: 15 additions & 6 deletions R/data_tabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
#' percentages to be calculated. Only applies to crosstables, i.e. when `by` is
#' not `NULL`. Can be `"row"` (row percentages), `"column"` (column percentages)
#' or `"full"` (to calculate relative frequencies for the full table).
#' @param add_total For crosstables (i.e. when `by` is not `NULL`), a row and
#' column with the total N values are added to the data frame. `add_total` has
#' no effect in `as.data.frame()` for simple frequency tables.
#' @param ... not used.
#' @inheritParams extract_column_names
#'
Expand Down Expand Up @@ -397,8 +394,17 @@ insight::print_md


#' @rdname data_tabulate
#' @param add_total For crosstables (i.e. when `by` is not `NULL`), a row and
#' column with the total N values are added to the data frame. `add_total` has
#' no effect in `as.data.frame()` for simple frequency tables.
#' @inheritParams base::as.data.frame
#' @export
as.data.frame.datawizard_tables <- function(x, add_total = FALSE, ...) {
as.data.frame.datawizard_tables <- function(x,
row.names = NULL,
optional = FALSE,
...,
stringsAsFactors = FALSE,
add_total = FALSE) {
# extract variables of frequencies
selected_vars <- unlist(lapply(x, function(i) attributes(i)$varname))
# coerce to data frame, remove rownames
Expand All @@ -417,11 +423,14 @@ as.data.frame.datawizard_tables <- function(x, add_total = FALSE, ...) {
out
})
# create nested data frame
data.frame(
result <- data.frame(
var = selected_vars,
table = I(data_frames),
stringsAsFactors = FALSE
stringsAsFactors = stringsAsFactors
)
# consider additional arguments
rownames(result) <- row.names
result
}

#' @export
Expand Down
23 changes: 22 additions & 1 deletion man/data_tabulate.Rd

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

0 comments on commit 953adc3

Please sign in to comment.