Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 3, 2024
1 parent c6b475a commit 14d16d8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 122 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: datawizard
Title: Easy Data Wrangling and Statistical Transformations
Version: 0.13.0.9
Version: 0.13.0.10
Authors@R: c(
person("Indrajeet", "Patil", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-1995-6531")),
Expand Down
177 changes: 59 additions & 118 deletions tests/testthat/_snaps/data_codebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,48 +143,29 @@
Output
efc (100 rows and 5 variables, 5 shown)
ID | Name | Label | Type
---+----------+------------------------------------------+------------
1 | c12hour | average number of hours of care per week | numeric
---+----------+------------------------------------------+------------
2 | e16sex | elder's gender | numeric
---+----------+------------------------------------------+------------
---+----------+------------------------------------------+------------
3 | e42dep | elder's dependency | categorical
---+----------+------------------------------------------+------------
---+----------+------------------------------------------+------------
---+----------+------------------------------------------+------------
---+----------+------------------------------------------+------------
4 | c172code | carer's level of education | numeric
---+----------+------------------------------------------+------------
---+----------+------------------------------------------+------------
---+----------+------------------------------------------+------------
5 | neg_c_7 | Negative impact with 7 items | numeric
----------------------------------------------------------------------
ID | Missings | Values | Value Labels | N
---+------------+----------+---------------------------------+-----------
1 | 2 (2.0%) | [5, 168] | | 98
---+------------+----------+---------------------------------+-----------
2 | 0 (0.0%) | 1 | male | 46 (46.0%)
| | 2 | female | 54 (54.0%)
---+------------+----------+---------------------------------+-----------
3 | 3 (3.0%) | 1 | independent | 2 ( 2.1%)
| | 2 | slightly dependent | 4 ( 4.1%)
| | 3 | moderately dependent | 28 (28.9%)
| | 4 | severely dependent | 63 (64.9%)
---+------------+----------+---------------------------------+-----------
4 | 10 (10.0%) | 1 | low level of education | 8 ( 8.9%)
| | 2 | intermediate level of education | 66 (73.3%)
| | 3 | high level of education | 16 (17.8%)
---+------------+----------+---------------------------------+-----------
5 | 3 (3.0%) | [7, 28] | | 97
-------------------------------------------------------------------------
ID | Name | Label | Type | Missings | Values | Value Labels | N
---+----------+------------------------------------------+-------------+------------+----------+---------------------------------+-----------
1 | c12hour | average number of hours of care per week | numeric | 2 (2.0%) | [5, 168] | | 98
---+----------+------------------------------------------+-------------+------------+----------+---------------------------------+-----------
2 | e16sex | elder's gender | numeric | 0 (0.0%) | 1 | male | 46 (46.0%)
| | | | | 2 | female | 54 (54.0%)
---+----------+------------------------------------------+-------------+------------+----------+---------------------------------+-----------
3 | e42dep | elder's dependency | categorical | 3 (3.0%) | 1 | independent | 2 ( 2.1%)
| | | | | 2 | slightly dependent | 4 ( 4.1%)
| | | | | 3 | moderately dependent | 28 (28.9%)
| | | | | 4 | severely dependent | 63 (64.9%)
---+----------+------------------------------------------+-------------+------------+----------+---------------------------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%) | 1 | low level of education | 8 ( 8.9%)
| | | | | 2 | intermediate level of education | 66 (73.3%)
| | | | | 3 | high level of education | 16 (17.8%)
---+----------+------------------------------------------+-------------+------------+----------+---------------------------------+-----------
5 | neg_c_7 | Negative impact with 7 items | numeric | 3 (3.0%) | [7, 28] | | 97
---------------------------------------------------------------------------------------------------------------------------------------------

---

Code
print(data_codebook(efc))
print(data_codebook(efc), table_width = "auto")
Output
efc (100 rows and 5 variables, 5 shown)
Expand Down Expand Up @@ -233,50 +214,30 @@
Output
efc (100 rows and 5 variables, 5 shown)
ID | Name | Label | Type | Missings
---+----------+------------------------------+-------------+-----------
1 | c12hour | average number of hours of | numeric | 2 (2.0%)
| | care per week | |
---+----------+------------------------------+-------------+-----------
2 | e16sex | elder's gender | numeric | 0 (0.0%)
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
3 | e42dep | elder's dependency | categorical | 3 (3.0%)
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%)
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
5 | neg_c_7 | Negative impact with 7 items | numeric | 3 (3.0%)
-----------------------------------------------------------------------
ID | Values | Value Labels | N
---+----------+---------------------------------+-----------
1 | [5, 168] | | 98
---+----------+---------------------------------+-----------
---+----------+---------------------------------+-----------
2 | 1 | male | 46 (46.0%)
| 2 | female | 54 (54.0%)
---+----------+---------------------------------+-----------
3 | 1 | independent | 2 ( 2.1%)
| 2 | slightly dependent | 4 ( 4.1%)
| 3 | moderately dependent | 28 (28.9%)
| 4 | severely dependent | 63 (64.9%)
---+----------+---------------------------------+-----------
4 | 1 | low level of education | 8 ( 8.9%)
| 2 | intermediate level of education | 66 (73.3%)
| 3 | high level of education | 16 (17.8%)
---+----------+---------------------------------+-----------
5 | [7, 28] | | 97
------------------------------------------------------------
ID | Name | Label | Type | Missings | Values | Value Labels | N
---+----------+------------------------------+-------------+------------+----------+---------------------------------+-----------
1 | c12hour | average number of hours of | numeric | 2 (2.0%) | [5, 168] | | 98
| | care per week | | | | |
---+----------+------------------------------+-------------+------------+----------+---------------------------------+-----------
2 | e16sex | elder's gender | numeric | 0 (0.0%) | 1 | male | 46 (46.0%)
| | | | | 2 | female | 54 (54.0%)
---+----------+------------------------------+-------------+------------+----------+---------------------------------+-----------
3 | e42dep | elder's dependency | categorical | 3 (3.0%) | 1 | independent | 2 ( 2.1%)
| | | | | 2 | slightly dependent | 4 ( 4.1%)
| | | | | 3 | moderately dependent | 28 (28.9%)
| | | | | 4 | severely dependent | 63 (64.9%)
---+----------+------------------------------+-------------+------------+----------+---------------------------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%) | 1 | low level of education | 8 ( 8.9%)
| | | | | 2 | intermediate level of education | 66 (73.3%)
| | | | | 3 | high level of education | 16 (17.8%)
---+----------+------------------------------+-------------+------------+----------+---------------------------------+-----------
5 | neg_c_7 | Negative impact with 7 items | numeric | 3 (3.0%) | [7, 28] | | 97
---------------------------------------------------------------------------------------------------------------------------------

---

Code
print(out)
print(out, table_width = "auto")
Output
efc (100 rows and 5 variables, 5 shown)
Expand Down Expand Up @@ -327,50 +288,30 @@
Output
efc (100 rows and 5 variables, 5 shown)
ID | Name | Label | Type | Missings
---+----------+------------------------------+-------------+-----------
1 | c12hour | average number of hours of | numeric | 2 (2.0%)
| | care per week | |
---+----------+------------------------------+-------------+-----------
2 | e16sex | elder's gender | numeric | 0 (0.0%)
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
3 | e42dep | elder's dependency | categorical | 3 (3.0%)
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%)
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
---+----------+------------------------------+-------------+-----------
5 | neg_c_7 | Negative impact with 7 items | numeric | 3 (3.0%)
-----------------------------------------------------------------------
ID | Values | Value Labels | N
---+----------+------------------+-----------
1 | [5, 168] | | 98
---+----------+------------------+-----------
---+----------+------------------+-----------
2 | 1 | male | 46 (46.0%)
| 2 | female | 54 (54.0%)
---+----------+------------------+-----------
3 | 1 | independent | 2 ( 2.1%)
| 2 | slightly... | 4 ( 4.1%)
| 3 | moderately... | 28 (28.9%)
| 4 | severely... | 63 (64.9%)
---+----------+------------------+-----------
4 | 1 | low level of... | 8 ( 8.9%)
| 2 | intermediate... | 66 (73.3%)
| 3 | high level of... | 16 (17.8%)
---+----------+------------------+-----------
5 | [7, 28] | | 97
---------------------------------------------
ID | Name | Label | Type | Missings | Values | Value Labels | N
---+----------+------------------------------+-------------+------------+----------+------------------+-----------
1 | c12hour | average number of hours of | numeric | 2 (2.0%) | [5, 168] | | 98
| | care per week | | | | |
---+----------+------------------------------+-------------+------------+----------+------------------+-----------
2 | e16sex | elder's gender | numeric | 0 (0.0%) | 1 | male | 46 (46.0%)
| | | | | 2 | female | 54 (54.0%)
---+----------+------------------------------+-------------+------------+----------+------------------+-----------
3 | e42dep | elder's dependency | categorical | 3 (3.0%) | 1 | independent | 2 ( 2.1%)
| | | | | 2 | slightly... | 4 ( 4.1%)
| | | | | 3 | moderately... | 28 (28.9%)
| | | | | 4 | severely... | 63 (64.9%)
---+----------+------------------------------+-------------+------------+----------+------------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%) | 1 | low level of... | 8 ( 8.9%)
| | | | | 2 | intermediate... | 66 (73.3%)
| | | | | 3 | high level of... | 16 (17.8%)
---+----------+------------------------------+-------------+------------+----------+------------------+-----------
5 | neg_c_7 | Negative impact with 7 items | numeric | 3 (3.0%) | [7, 28] | | 97
------------------------------------------------------------------------------------------------------------------

---

Code
print(out)
print(out, table_width = "auto")
Output
efc (100 rows and 5 variables, 5 shown)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-data_codebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ test_that("data_codebook iris, select, ID", {

test_that("data_codebook efc", {
expect_snapshot(print(data_codebook(efc), table_width = Inf))
expect_snapshot(print(data_codebook(efc)))
expect_snapshot(print(data_codebook(efc), table_width = "auto"))
})


test_that("data_codebook efc, variable_label_width", {
out <- data_codebook(efc, variable_label_width = 30)
expect_snapshot(print(out, table_width = Inf))
expect_snapshot(print(out))
expect_snapshot(print(out, table_width = "auto"))
})


test_that("data_codebook efc, value_label_width", {
out <- data_codebook(efc, variable_label_width = 30, value_label_width = 15)
expect_snapshot(print(out, table_width = Inf))
expect_snapshot(print(out))
expect_snapshot(print(out, table_width = "auto"))
})


Expand Down

0 comments on commit 14d16d8

Please sign in to comment.