diff --git a/DESCRIPTION b/DESCRIPTION index 4bf0334b..01f21315 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -86,6 +86,7 @@ Collate: 'format_citation.R' 'format_formula.R' 'format_model.R' + 'reexports.r' 'report-package.R' 'utils_combine_tables.R' 'report.lm.R' diff --git a/NAMESPACE b/NAMESPACE index 1e8f7862..5071a685 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,6 +25,8 @@ S3method(print,report_sample) S3method(print,report_statistics) S3method(print,report_table) S3method(print,report_text) +S3method(print_html,report_sample) +S3method(print_md,report_sample) S3method(report,MixMod) S3method(report,anova) S3method(report,aov) @@ -273,6 +275,8 @@ export(format_citation) export(format_formula) export(format_model) export(is.report) +export(print_html) +export(print_md) export(report) export(report_date) export(report_effectsize) @@ -292,3 +296,5 @@ export(report_system) export(report_table) export(report_text) importFrom(insight,display) +importFrom(insight,print_html) +importFrom(insight,print_md) diff --git a/R/reexports.r b/R/reexports.r new file mode 100644 index 00000000..eff24b19 --- /dev/null +++ b/R/reexports.r @@ -0,0 +1,13 @@ +# ----------------------- insight ------------------------------------- + +#' @importFrom insight print_html +#' @export +insight::print_html + +#' @importFrom insight print_md +#' @export +insight::print_md + +#' @importFrom insight display +#' @export +insight::display diff --git a/R/report_sample.R b/R/report_sample.R index af4da263..e21840ce 100644 --- a/R/report_sample.R +++ b/R/report_sample.R @@ -302,7 +302,7 @@ report_sample <- function(data, if (!is.null(ci)) { ci_low_high <- .ci_proportion(x, proportions, weights, ci, ci_method, ci_correct) .summary <- sprintf( - "%.1f (%.1f, %.1f)", + "%.1f [%.1f, %.1f]", 100 * proportions, 100 * ci_low_high$ci_low, 100 * ci_low_high$ci_high @@ -394,6 +394,25 @@ print.report_sample <- function(x, ...) { cat(insight::export_table(x)) } +#' @export +print_html.report_sample <- function(x, ...) { + if (isTRUE(attributes(x)$weighted)) { + caption <- "Descriptive Statistics (weighted)" + } else { + caption <- "Descriptive Statistics" + } + insight::export_table(x, format = "html", caption = caption, ...) +} + +#' @export +print_md.report_sample <- function(x, ...) { + if (isTRUE(attributes(x)$weighted)) { + caption <- "Descriptive Statistics (weighted)" + } else { + caption <- "Descriptive Statistics" + } + insight::export_table(x, format = "markdown", caption = caption, ...) +} # helper for weighted stuff -------------------------- diff --git a/R/report_table.R b/R/report_table.R index ecab4f84..4a77098e 100644 --- a/R/report_table.R +++ b/R/report_table.R @@ -200,10 +200,3 @@ display.report_table <- function(object, ...) { footer } - - -# Reexports models ------------------------ - -#' @importFrom insight display -#' @export -insight::display diff --git a/man/reexports.Rd b/man/reexports.Rd index 664bdf2c..7375b9ee 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -1,8 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/report_table.R +% Please edit documentation in R/reexports.r \docType{import} \name{reexports} \alias{reexports} +\alias{print_html} +\alias{print_md} \alias{display} \title{Objects exported from other packages} \keyword{internal} @@ -11,6 +13,6 @@ These objects are imported from other packages. Follow the links below to see their documentation. \describe{ - \item{insight}{\code{\link[insight]{display}}} + \item{insight}{\code{\link[insight]{display}}, \code{\link[insight:display]{print_html}}, \code{\link[insight:display]{print_md}}} }} diff --git a/tests/testthat/_snaps/windows/report_sample.md b/tests/testthat/_snaps/windows/report_sample.md index 2e047a35..8d762ade 100644 --- a/tests/testthat/_snaps/windows/report_sample.md +++ b/tests/testthat/_snaps/windows/report_sample.md @@ -117,9 +117,9 @@ Variable | Summary ------------------------------------------- Mean Sepal.Length (SD) | 5.84 (0.83) - Species [setosa], % | 33.3 (25.8, 40.9) - Species [versicolor], % | 33.3 (25.8, 40.9) - Species [virginica], % | 33.3 (25.8, 40.9) + Species [setosa], % | 33.3 [25.8, 40.9] + Species [versicolor], % | 33.3 [25.8, 40.9] + Species [virginica], % | 33.3 [25.8, 40.9] --- @@ -132,9 +132,9 @@ Variable | Summary ------------------------------------------- Mean Sepal.Length (SD) | 5.84 (0.83) - Species [setosa], % | 33.3 (26.3, 41.2) - Species [versicolor], % | 33.3 (26.3, 41.2) - Species [virginica], % | 33.3 (26.3, 41.2) + Species [setosa], % | 33.3 [26.3, 41.2] + Species [versicolor], % | 33.3 [26.3, 41.2] + Species [virginica], % | 33.3 [26.3, 41.2] --- @@ -145,7 +145,7 @@ Variable | Summary ------------------------- - x [1], % | 2.9 (1.9, 3.9) + x [1], % | 2.9 [1.9, 3.9] --- @@ -156,7 +156,7 @@ Variable | Summary ------------------------- - x [1], % | 2.9 (2.0, 4.1) + x [1], % | 2.9 [2.0, 4.1] --- @@ -167,7 +167,7 @@ Variable | Summary ------------------------- - x [1], % | 2.9 (1.8, 4.0) + x [1], % | 2.9 [1.8, 4.0] --- @@ -178,7 +178,7 @@ Variable | Summary ------------------------- - x [1], % | 2.9 (2.0, 4.2) + x [1], % | 2.9 [2.0, 4.2] # report_sample group_by