-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_operators.R
87 lines (72 loc) · 3.17 KB
/
test_operators.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
test_operators <- function() {
d <- wrapr::build_frame(
"model_id", "measure", "value" |
1 , "AUC" , 0.7 |
1 , "R2" , 0.4 |
2 , "AUC" , 0.8 |
2 , "R2" , 0.5 )
d2 <- wrapr::build_frame(
"model_id", "AUC", "R2" |
1 , 0.7 , 0.4 |
2 , 0.8 , 0.5 )
transform <- rowrecs_to_blocks_spec(
wrapr::qchar_frame(
measure, value |
AUC , "AUC" |
R2 , "R2" ),
recordKeys = "model_id")
d %//% t(transform) -> r
expect_true(wrapr::check_equiv_frames(d2, r))
d %//% t(transform) %**% transform -> r
expect_true(wrapr::check_equiv_frames(d, r))
r <- rowrecs_to_blocks(d2,
controlTable = transform$controlTable,
controlTableKeys = transform$controlTableKeys,
columnsToCopy = transform$recordKeys,
checkNames = TRUE,
strict = TRUE,
checkKeys = TRUE)
expect_true(wrapr::check_equiv_frames(d, r))
r <- blocks_to_rowrecs(d,
keyColumns = transform$recordKeys,
controlTable = transform$controlTable,
controlTableKeys = transform$controlTableKeys,
checkNames = TRUE,
strict = TRUE,
checkKeys = TRUE)
expect_true(wrapr::check_equiv_frames(d2, r))
if(requireNamespace("DBI", quietly = TRUE) ||
requireNamespace("RSQLite", quietly = TRUE)) {
my_db <- DBI::dbConnect(RSQLite::SQLite(),
":memory:")
d_db <- rquery::rq_copy_to(my_db, "d_db", d,
temporary = TRUE, overwrite = TRUE)
d2_db <- rquery::rq_copy_to(my_db, "d2_db", d2,
temporary = TRUE, overwrite = TRUE)
d_db %//% t(transform) %.>% rquery::execute(my_db, .) -> r
expect_true(wrapr::check_equiv_frames(d2, r))
d_db %//% t(transform) %**% transform %.>% rquery::execute(my_db, .) -> r
expect_true(wrapr::check_equiv_frames(d, r))
d_db %.>% .(t(transform)) %.>% rquery::execute(my_db, .) -> r
expect_true(wrapr::check_equiv_frames(d2, r))
r <- rowrecs_to_blocks(d2_db,
controlTable = transform$controlTable,
controlTableKeys = transform$controlTableKeys,
columnsToCopy = transform$recordKeys,
checkNames = TRUE,
strict = TRUE,
checkKeys = TRUE) %.>% rquery::execute(my_db, .)
expect_true(wrapr::check_equiv_frames(d, r))
r <- blocks_to_rowrecs(d_db,
keyColumns = transform$recordKeys,
controlTable = transform$controlTable,
controlTableKeys = transform$controlTableKeys,
checkNames = TRUE,
strict = TRUE,
checkKeys = TRUE) %.>% rquery::execute(my_db, .)
expect_true(wrapr::check_equiv_frames(d2, r))
DBI::dbDisconnect(my_db)
}
invisible(NULL)
}
test_operators()