Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 3, 2024
1 parent 5081ee7 commit f1f8cd7
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 0 deletions.
224 changes: 224 additions & 0 deletions tests/testthat/_snaps/export_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,227 @@
5 | | 97 |
-------------------------------------------------

---

Code
print(export_table(out, table_width = 60, remove_duplicates = TRUE, empty_line = "-",
cross = "+"))
Output
ID | Name | Label
---+----------+-----------------------------------------
1 | c12hour | average number of hours of care per week
---+----------+-----------------------------------------
2 | e15relat | relationship to elder
---+----------+-----------------------------------------
3 | e16sex | elder's gender
---+----------+-----------------------------------------
4 | e17age | elder' age
--------------------------------------------------------
ID | Type | Missings | Values
---+---------+-----------+----------
1 | numeric | 6 (0.7%) | [4, 168]
---+---------+-----------+----------
2 | numeric | 7 (0.8%) | 1
| | | 2
| | | 3
| | | 4
| | | 5
| | | 6
| | | 7
| | | 8
---+---------+-----------+----------
3 | numeric | 7 (0.8%) | 1
| | | 2
---+---------+-----------+----------
4 | numeric | 17 (1.9%) | [65, 103]
------------------------------------
ID | Value Labels | N | Prop
---+-------------------------+-----+------
1 | | 902 |
---+-------------------------+-----+------
2 | spouse/partner | 171 | 19.0%
| child | 473 | 52.5%
| sibling | 29 | 3.2%
| daughter or son -in-law | 85 | 9.4%
| ancle/aunt | 23 | 2.6%
| nephew/niece | 22 | 2.4%
| cousin | 6 | 0.7%
| other, specify | 92 | 10.2%
---+-------------------------+-----+------
3 | male | 296 | 32.9%
| female | 605 | 67.1%
---+-------------------------+-----+------
4 | | 891 |
------------------------------------------

---

Code
print(export_table(out, table_width = 60, remove_duplicates = FALSE,
empty_line = "-", cross = "+"))
Output
ID | Name | Label
---+----------+-----------------------------------------
1 | c12hour | average number of hours of care per week
---+----------+-----------------------------------------
2 | e15relat | relationship to elder
| |
| |
| |
| |
| |
| |
| |
---+----------+-----------------------------------------
3 | e16sex | elder's gender
| |
---+----------+-----------------------------------------
4 | e17age | elder' age
--------------------------------------------------------
ID | Type | Missings | Values
---+---------+-----------+----------
1 | numeric | 6 (0.7%) | [4, 168]
---+---------+-----------+----------
2 | numeric | 7 (0.8%) | 1
| | | 2
| | | 3
| | | 4
| | | 5
| | | 6
| | | 7
| | | 8
---+---------+-----------+----------
3 | numeric | 7 (0.8%) | 1
| | | 2
---+---------+-----------+----------
4 | numeric | 17 (1.9%) | [65, 103]
------------------------------------
ID | Value Labels | N | Prop
---+-------------------------+-----+------
1 | | 902 |
---+-------------------------+-----+------
2 | spouse/partner | 171 | 19.0%
| child | 473 | 52.5%
| sibling | 29 | 3.2%
| daughter or son -in-law | 85 | 9.4%
| ancle/aunt | 23 | 2.6%
| nephew/niece | 22 | 2.4%
| cousin | 6 | 0.7%
| other, specify | 92 | 10.2%
---+-------------------------+-----+------
3 | male | 296 | 32.9%
| female | 605 | 67.1%
---+-------------------------+-----+------
4 | | 891 |
------------------------------------------

---

Code
print(export_table(out, table_width = 60, remove_duplicates = TRUE, empty_line = "-",
cross = "+"))
Output
ID | Name | Label
---+----------+-----------------------------------------
1 | c12hour | average number of hours of care per week
---+----------+-----------------------------------------
2 | e15relat | relationship to elder
---+----------+-----------------------------------------
3 | e16sex | elder's gender
--------------------------------------------------------
ID | Type | Missings | Values
---+---------+----------+---------
1 | numeric | 6 (0.7%) | [4, 168]
---+---------+----------+---------
2 | numeric | 7 (0.8%) | 1
| | | 2
| | | 3
| | | 4
| | | 5
| | | 6
| | | 7
| | | 8
---+---------+----------+---------
3 | numeric | 7 (0.8%) | 1
| | | 2
----------------------------------
ID | Value Labels | N | Prop
---+-------------------------+-----+------
1 | | 902 |
---+-------------------------+-----+------
2 | spouse/partner | 171 | 19.0%
| child | 473 | 52.5%
| sibling | 29 | 3.2%
| daughter or son -in-law | 85 | 9.4%
| ancle/aunt | 23 | 2.6%
| nephew/niece | 22 | 2.4%
| cousin | 6 | 0.7%
| other, specify | 92 | 10.2%
---+-------------------------+-----+------
3 | male | 296 | 32.9%
| female | 605 | 67.1%
------------------------------------------

---

Code
print(export_table(out, table_width = 60, remove_duplicates = FALSE,
empty_line = "-", cross = "+"))
Output
ID | Name | Label
---+----------+-----------------------------------------
1 | c12hour | average number of hours of care per week
---+----------+-----------------------------------------
2 | e15relat | relationship to elder
| |
| |
| |
| |
| |
| |
| |
---+----------+-----------------------------------------
3 | e16sex | elder's gender
| |
--------------------------------------------------------
ID | Type | Missings | Values
---+---------+----------+---------
1 | numeric | 6 (0.7%) | [4, 168]
---+---------+----------+---------
2 | numeric | 7 (0.8%) | 1
| | | 2
| | | 3
| | | 4
| | | 5
| | | 6
| | | 7
| | | 8
---+---------+----------+---------
3 | numeric | 7 (0.8%) | 1
| | | 2
----------------------------------
ID | Value Labels | N | Prop
---+-------------------------+-----+------
1 | | 902 |
---+-------------------------+-----+------
2 | spouse/partner | 171 | 19.0%
| child | 473 | 52.5%
| sibling | 29 | 3.2%
| daughter or son -in-law | 85 | 9.4%
| ancle/aunt | 23 | 2.6%
| nephew/niece | 22 | 2.4%
| cousin | 6 | 0.7%
| other, specify | 92 | 10.2%
---+-------------------------+-----+------
3 | male | 296 | 32.9%
| female | 605 | 67.1%
------------------------------------------

11 changes: 11 additions & 0 deletions tests/testthat/test-export_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,15 @@ test_that("export_table, table_width, remove duplicated empty lines", {
expect_snapshot(print(export_table(out, table_width = 60, empty_line = "-", remove_duplicates = TRUE)))
expect_snapshot(print(export_table(out, table_width = 60, empty_line = "-", sep = " | ", remove_duplicates = TRUE)))
expect_snapshot(print(export_table(out, table_width = 60, empty_line = "-", cross = "+", remove_duplicates = TRUE)))

skip_if_not_installed("ggeffects")
data(efc, package = "ggeffects")
out <- datawizard::data_codebook(efc[, 1:4])
out$.row_id <- NULL
expect_snapshot(print(export_table(out, table_width = 60, remove_duplicates = TRUE, empty_line = "-", cross = "+")))
expect_snapshot(print(export_table(out, table_width = 60, remove_duplicates = FALSE, empty_line = "-", cross = "+")))
out <- datawizard::data_codebook(efc[, 1:3])
out$.row_id <- NULL
expect_snapshot(print(export_table(out, table_width = 60, remove_duplicates = TRUE, empty_line = "-", cross = "+")))
expect_snapshot(print(export_table(out, table_width = 60, remove_duplicates = FALSE, empty_line = "-", cross = "+")))
})

0 comments on commit f1f8cd7

Please sign in to comment.