Skip to content

Commit

Permalink
print markdown method
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 13, 2024
1 parent f34e78c commit 755f7ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ S3method(print_md,data_codebook)
S3method(print_md,dw_data_peek)
S3method(print_md,dw_data_tabulate)
S3method(print_md,dw_data_tabulates)
S3method(print_md,dw_data_xtabulate)
S3method(ranktransform,data.frame)
S3method(ranktransform,factor)
S3method(ranktransform,grouped_df)
Expand Down
24 changes: 23 additions & 1 deletion R/data_xtabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ format.dw_data_xtabulate <- function(x, format = "text", digits = 1, big_mark =
# Remove ".00" from numbers
ftab$Total <- gsub("\\.00$", "", as.character(total_column))
# for text format, insert "empty row" before last total row
if (identical(format, "text")) {
if (identical(format, "text") || identical(format, "markdown")) {
sub <- as.data.frame(t(data.frame(

Check warning on line 155 in R/data_xtabulate.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_xtabulate.R,line=155,col=5,[object_overwrite_linter] 'sub' is an exported object from package 'base'. Avoid re-using such symbols.
rep("", ncol(ftab)),
c("Total", as.character(total_row)),
Expand Down Expand Up @@ -197,6 +197,28 @@ print.dw_data_xtabulate <- function(x, big_mark = NULL, ...) {
}


#' @export
print_md.dw_data_xtabulate <- function(x, big_mark = NULL, ...) {
# grouped data? if yes, add information on grouping factor
if (is.null(x[["Group"]])) {
caption <- NULL
} else {
caption <- paste0("Grouped by ", x[["Group"]][1])
x$Group <- NULL
}

# print table
insight::export_table(
format(x, format = "markdown", big_mark = big_mark, ...),
cross = "+",
missing = "<NA>",
caption = caption,
empty_line = "-",
format = "markdown"
)
}


#' @export
print_html.dw_data_xtabulate <- function(x, big_mark = NULL, ...) {
# grouped data? if yes, add information on grouping factor
Expand Down

0 comments on commit 755f7ca

Please sign in to comment.