Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Dec 23, 2024
1 parent c962d2f commit dbac6dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 67 deletions.
4 changes: 2 additions & 2 deletions R/data_xtabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ print_html.datawizard_crosstab <- function(x, big_mark = NULL, ...) {

# prepare table arguments
fun_args <- list(
format(x, big_mark = big_mark, ...),
format(x, big_mark = big_mark, format = format, ...),
caption = caption,
format = format
)
Expand Down Expand Up @@ -277,7 +277,7 @@ print_html.datawizard_crosstabs <- function(x, big_mark = NULL, ...) {

.print_text_tables <- function(x, big_mark = NULL, format = "text", ...) {
if (length(x) == 1) {
print(x[[1]], big_mark = big_mark, ...)
.print_text_table(x[[1]], big_mark = big_mark, format = format, ...)
} else {
x <- lapply(x, function(i) {
# grouped data? if yes, add information on grouping factor
Expand Down
67 changes: 2 additions & 65 deletions tests/testthat/_snaps/data_tabulate.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@
<NA> | 5 (50.0%) | 4 (40.0%) | 1 (10.0%) | 10
---------+------------+------------+-----------+------
Total | 45 | 50 | 5 | 100

---

Expand All @@ -326,7 +325,6 @@
3 | 4 (26.7%) | 11 (73.3%) | 15
---------+------------+------------+------
Total | 40 | 46 | 86

---

Expand All @@ -342,7 +340,6 @@
<NA> | 8 (57.1%) | 5 (35.7%) | 1 (7.1%) | 14
---------+------------+------------+-----------+------
Total | 48 | 51 | 7 | 105

---

Expand All @@ -357,7 +354,6 @@
3 | 3 (21.4%) | 11 (78.6%) | 14
---------+------------+------------+------
Total | 40 | 46 | 86

---

Expand All @@ -372,7 +368,6 @@
<NA> | 5 (11.1%) | 4 (8.0%) | 1 (20.0%) | 10
---------+------------+------------+-----------+------
Total | 45 | 50 | 5 | 100

---

Expand All @@ -387,7 +382,6 @@
3 | 4 (10.0%) | 11 (23.9%) | 15
---------+------------+------------+------
Total | 40 | 46 | 86

---

Expand All @@ -403,7 +397,6 @@
<NA> | 8 (16.7%) | 5 (9.8%) | 1 (14.3%) | 14
---------+------------+------------+-----------+------
Total | 48 | 51 | 7 | 105

---

Expand All @@ -418,62 +411,6 @@
3 | 3 (7.5%) | 11 (23.9%) | 14
---------+------------+------------+------
Total | 40 | 46 | 86

# data_tabulate, cross tables, grouped df

Code
print(data_tabulate(grp, "c172code", by = "e16sex", proportions = "row"))
Output
Grouped by e42dep (1)
c172code | male | <NA> | Total
---------+------------+------------+------
2 | 2 (100.0%) | 0 (0.0%) | 2
<NA> | 0 (0%) | 0 (0%) | 0
---------+------------+------------+------
Total | 2 | 0 | 2
Grouped by e42dep (2)
c172code | male | female | <NA> | Total
---------+-----------+-----------+-----------+------
2 | 2 (50.0%) | 2 (50.0%) | 0 (0.0%) | 4
<NA> | 0 (0%) | 0 (0%) | 0 (0%) | 0
---------+-----------+-----------+-----------+------
Total | 2 | 2 | 0 | 4
Grouped by e42dep (3)
c172code | male | female | <NA> | Total
---------+-----------+------------+-----------+------
1 | 2 (50.0%) | 2 (50.0%) | 0 (0.0%) | 4
2 | 4 (25.0%) | 11 (68.8%) | 1 (6.2%) | 16
3 | 1 (16.7%) | 5 (83.3%) | 0 (0.0%) | 6
<NA> | 1 (50.0%) | 0 (0.0%) | 1 (50.0%) | 2
---------+-----------+------------+-----------+------
Total | 8 | 18 | 2 | 28
Grouped by e42dep (4)
c172code | male | female | <NA> | Total
---------+------------+------------+-----------+------
1 | 3 (75.0%) | 0 (0.0%) | 1 (25.0%) | 4
2 | 23 (54.8%) | 18 (42.9%) | 1 (2.4%) | 42
3 | 3 (30.0%) | 6 (60.0%) | 1 (10.0%) | 10
<NA> | 3 (42.9%) | 4 (57.1%) | 0 (0.0%) | 7
---------+------------+------------+-----------+------
Total | 32 | 28 | 3 | 63
Grouped by e42dep (NA)
c172code | male | female | <NA> | Total
---------+------------+------------+------------+------
2 | 0 (0.0%) | 2 (100.0%) | 0 (0.0%) | 2
<NA> | 1 (100.0%) | 0 (0.0%) | 0 (0.0%) | 1
---------+------------+------------+------------+------
Total | 1 | 2 | 0 | 3

# data_tabulate, cross tables, markdown

Expand All @@ -485,7 +422,7 @@
[3] "|1 | 5 (5.0%)| 2 (2.0%)|1 (1.0%) | 8|"
[4] "|2 | 31 (31.0%)| 33 (33.0%)|2 (2.0%) | 66|"
[5] "|3 | 4 (4.0%)| 11 (11.0%)|1 (1.0%) | 16|"
[6] "|<NA> | 5 (5.0%)| 4 (4.0%)|1 (1.0%) | 10|"
[6] "|(NA) | 5 (5.0%)| 4 (4.0%)|1 (1.0%) | 10|"
[7] "| | | | | |"
[8] "|Total | 45| 50| 5 | 100|"
attr(,"format")
Expand Down Expand Up @@ -522,7 +459,7 @@
[3] "|1 | 5 (4.8%)| 3 (2.9%)|2 (1.9%) | 10|"
[4] "|2 | 32 (30.5%)| 32 (30.5%)|3 (2.9%) | 67|"
[5] "|3 | 3 (2.9%)| 11 (10.5%)|1 (1.0%) | 15|"
[6] "|<NA> | 8 (7.6%)| 5 (4.8%)|1 (1.0%) | 14|"
[6] "|(NA) | 8 (7.6%)| 5 (4.8%)|1 (1.0%) | 14|"
[7] "| | | | | |"
[8] "|Total | 48| 51| 7 | 105|"
attr(,"format")
Expand Down

0 comments on commit dbac6dd

Please sign in to comment.