forked from SwissClinicalTrialOrganisation/secuTrialR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-read_secuTrial_raw.R
131 lines (114 loc) · 6.31 KB
/
test-read_secuTrial_raw.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
context("load full secuTrial export testing")
skip_on_cran()
short_export_location <- system.file("extdata", "sT_exports", "BMD",
"s_export_CSV-xls_BMD_short_en_utf8.zip",
package = "secuTrialR")
long_export_location <- system.file("extdata", "sT_exports", "BMD",
"s_export_CSV-xls_BMD_long_en_utf8.zip",
package = "secuTrialR")
no_add_id_export_location <- system.file("extdata", "sT_exports", "exp_opt",
"s_export_CSV-xls_CTU05_no_addid.zip",
package = "secuTrialR")
no_centre_info_export_location <- system.file("extdata", "sT_exports", "exp_opt",
"s_export_CSV-xls_CTU05_no_centre_info.zip",
package = "secuTrialR")
no_proj_setup_export_location <- system.file("extdata", "sT_exports", "exp_opt",
"s_export_CSV-xls_CTU05_no_proj_setup.zip",
package = "secuTrialR")
no_add_id_cent_proj_export_location <- system.file("extdata", "sT_exports", "exp_opt",
"s_export_CSV-xls_CTU05_no_addid_ctr_info_proj_setup.zip",
package = "secuTrialR")
all_info_export_location <- system.file("extdata", "sT_exports", "exp_opt",
"s_export_CSV-xls_CTU05_all_info.zip",
package = "secuTrialR")
only_col_names_export_location <- system.file("extdata", "sT_exports", "exp_opt",
"s_export_CSV-xls_CTU05_only_column_names.zip",
package = "secuTrialR")
sT_export_short <- read_secuTrial_raw(data_dir = short_export_location)
sT_export_long <- read_secuTrial_raw(data_dir = long_export_location)
sT_export_no_add_id <- read_secuTrial_raw(data_dir = no_add_id_export_location)
sT_export_no_centre_info <- read_secuTrial_raw(data_dir = no_centre_info_export_location)
sT_export_no_proj_setup <- read_secuTrial_raw(data_dir = no_proj_setup_export_location)
sT_export_no_add_id_cent_proj <- read_secuTrial_raw(data_dir = no_add_id_cent_proj_export_location)
sT_export_all_info <- read_secuTrial_raw(data_dir = all_info_export_location)
sT_export_only_col_names <- read_secuTrial_raw(data_dir = only_col_names_export_location)
# test length of list
test_that("All data tables loaded.", {
expect_equal(length(names(sT_export_short)), 14)
expect_equal(length(names(sT_export_long)), 14)
expect_equal(length(names(sT_export_no_add_id)), 32)
# one less because there is no centres table
expect_equal(length(names(sT_export_no_centre_info)), 31)
# 5 less // "fs", "is", "qs", "vp", "vpfs" are missing
expect_equal(length(names(sT_export_no_proj_setup)), 27)
# 6 less // "fs", "ctr", "is", "qs", "vp", "vpfs" are missing
expect_equal(length(names(sT_export_no_add_id_cent_proj)), 26)
expect_equal(length(names(sT_export_only_col_names)), 11)
expect_equal(length(names(sT_export_all_info)), 32)
})
# check dimensions of loaded data
test_that("Data dimensions are correct.", {
# dim CTU05
# newer exports contain additonal mnplang: 62 + 1 = 63
# 63 because everything is available
expect_equal(dim(sT_export_all_info$baseline), c(17, 63))
# older exports without mnplang: 62
# 61 because pat_id column has not been added
expect_equal(dim(sT_export_no_add_id$baseline), c(17, 61))
# 61 because centre column has not been added
expect_equal(dim(sT_export_no_centre_info$baseline), c(17, 61))
# 61 because visit_name column has not been added
expect_equal(dim(sT_export_no_proj_setup$baseline), c(17, 61))
# 59 because pat_id, centre, visit_name columns have not been added
expect_equal(dim(sT_export_no_add_id_cent_proj$baseline), c(17, 59))
expect_equal(dim(sT_export_only_col_names$ctu05baseline), c(17, 37))
# dim bone mineral density
expect_equal(dim(sT_export_short$bmd), dim(sT_export_long$dem00bmd))
expect_equal(dim(sT_export_long$dem00bmd), c(504, 27))
# dim centre
expect_equal(dim(sT_export_long$centre), dim(sT_export_short$ctr))
expect_equal(dim(sT_export_short$ctr), c(1, 3))
# dim casenode
expect_equal(dim(sT_export_long$casenodes), dim(sT_export_short$cn))
expect_equal(dim(sT_export_short$cn), c(113, 13))
})
# check add_id and lab_id
test_that("add_id and lab_id correctly determined", {
expect_true(sT_export_all_info$export_options$add_id)
expect_true(sT_export_no_centre_info$export_options$add_id)
expect_true(sT_export_no_proj_setup$export_options$add_id)
expect_false(sT_export_no_add_id$export_options$add_id)
expect_false(sT_export_no_add_id_cent_proj$export_options$add_id)
expect_false(sT_export_only_col_names$export_options$add_id)
expect_true(sT_export_short$export_options$add_id)
expect_true(sT_export_long$export_options$add_id)
expect_false(sT_export_short$export_options$lab_id)
expect_false(sT_export_long$export_options$lab_id)
})
# check centre info parsing
test_that("centre info correctly determined", {
expect_true(sT_export_all_info$export_options$centre_info)
expect_true(sT_export_no_proj_setup$export_options$centre_info)
expect_true(sT_export_no_add_id$export_options$centre_info)
expect_false(sT_export_no_centre_info$export_options$centre_info)
expect_false(sT_export_only_col_names$export_options$centre_info)
})
# check proj setup parsing
test_that("centre info correctly determined", {
expect_true(sT_export_all_info$export_options$proj_setup)
expect_false(sT_export_no_proj_setup$export_options$proj_setup)
expect_true(sT_export_no_add_id$export_options$proj_setup)
expect_true(sT_export_no_centre_info$export_options$proj_setup)
expect_false(sT_export_only_col_names$export_options$proj_setup)
})
# check fail "Column names"
test_that("No Column names failing", {
expect_error(read_secuTrial_raw(data_dir = system.file("extdata", "sT_exports", "BMD",
"s_export_CSV-xls_BMD_long_ref_en_utf8.zip",
package = "secuTrialR"))
)
})
# test missing file
test_that("Missing file exception.", {
expect_error(read_secuTrial("thisisnotafile.zip"))
})