Skip to content

Commit

Permalink
add print_html, brackets (#360)
Browse files Browse the repository at this point in the history
* add print_html, brackets

* move

* ...

* update snapshots
  • Loading branch information
strengejacke authored Apr 1, 2023
1 parent e951c28 commit f74b39b
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 20 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Collate:
'format_citation.R'
'format_formula.R'
'format_model.R'
'reexports.r'

This comment has been minimized.

Copy link
@IndrajeetPatil

IndrajeetPatil Apr 1, 2023

Member

The file extension here should be .R, and not .r.

'report-package.R'
'utils_combine_tables.R'
'report.lm.R'
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -292,3 +296,5 @@ export(report_system)
export(report_table)
export(report_text)
importFrom(insight,display)
importFrom(insight,print_html)
importFrom(insight,print_md)
13 changes: 13 additions & 0 deletions R/reexports.r
Original file line number Diff line number Diff line change
@@ -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
21 changes: 20 additions & 1 deletion R/report_sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 --------------------------
Expand Down
7 changes: 0 additions & 7 deletions R/report_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,3 @@ display.report_table <- function(object, ...) {

footer
}


# Reexports models ------------------------

#' @importFrom insight display
#' @export
insight::display
6 changes: 4 additions & 2 deletions man/reexports.Rd

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

20 changes: 10 additions & 10 deletions tests/testthat/_snaps/windows/report_sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

---

Expand All @@ -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]

---

Expand All @@ -145,7 +145,7 @@
Variable | Summary
-------------------------
x [1], % | 2.9 (1.9, 3.9)
x [1], % | 2.9 [1.9, 3.9]

---

Expand All @@ -156,7 +156,7 @@
Variable | Summary
-------------------------
x [1], % | 2.9 (2.0, 4.1)
x [1], % | 2.9 [2.0, 4.1]

---

Expand All @@ -167,7 +167,7 @@
Variable | Summary
-------------------------
x [1], % | 2.9 (1.8, 4.0)
x [1], % | 2.9 [1.8, 4.0]

---

Expand All @@ -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

Expand Down

0 comments on commit f74b39b

Please sign in to comment.