removed hash matching from tests to try to handle test errors on different systems

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-09-05 15:38:38 +02:00
parent c6f9737c91
commit db4bc4412b
No known key found for this signature in database
4 changed files with 1194 additions and 14 deletions

View File

@ -1,5 +1,3 @@
# Check the RCurl export --------------------------------------------------- # Check the RCurl export ---------------------------------------------------
test_that("JSON character vector from RCurl matches reference", { test_that("JSON character vector from RCurl matches reference", {
metadata <- metadata <-
@ -10,6 +8,168 @@ test_that("JSON character vector from RCurl matches reference", {
redcap_output_json1 <- REDCap_split(records, metadata) redcap_output_json1 <- REDCap_split(records, metadata)
expect_known_hash(redcap_output_json1, "2c8b6531597182af1248f92124161e0c") # expect_known_hash(redcap_output_json1, "2c8b6531597182af1248f92124161e0c")
# dput(redcap_output_json1)
expect_identical(
redcap_output_json1,
list(structure(list(
row = c(
"AMC Javelin", "Cadillac Fleetwood",
"Camaro Z28", "Chrysler Imperial", "Datsun 710", "Dodge Challenger",
"Duster 360", "Ferrari Dino", "Fiat 128", "Fiat X1-9", "Ford Pantera L",
"Honda Civic", "Hornet 4 Drive", "Hornet Sportabout", "Lincoln Continental",
"Lotus Europa", "Maserati Bora", "Mazda RX4", "Mazda RX4 Wag",
"Merc 230", "Merc 240D", "Merc 280", "Merc 280C", "Merc 450SE",
"Merc 450SL", "Merc 450SLC", "Pontiac Firebird", "Porsche 914-2",
"Toyota Corolla", "Toyota Corona", "Valiant", "Volvo 142E"
),
mpg = c(
"15.2", "10.4", "13.3", "14.7", "22.8", "15.5", "14.3",
"19.7", "32.4", "27.3", "15.8", "30.4", "21.4", "18.7", "10.4",
"30.4", "15", "21", "21", "22.8", "24.4", "19.2", "17.8",
"16.4", "17.3", "15.2", "19.2", "26", "33.9", "21.5", "18.1",
"21.4"
), cyl = c(
"8", "8", "8", "8", "4", "8", "8", "6",
"4", "4", "8", "4", "6", "8", "8", "4", "8", "6", "6", "4",
"4", "6", "6", "8", "8", "8", "8", "4", "4", "4", "6", "4"
), disp = c(
"304", "472", "350", "440", "108", "318", "360",
"145", "78.7", "79", "351", "75.7", "258", "360", "460",
"95.1", "301", "160", "160", "140.8", "146.7", "167.6", "167.6",
"275.8", "275.8", "275.8", "400", "120.3", "71.1", "120.1",
"225", "121"
), hp = c(
"150", "205", "245", "230", "93", "150",
"245", "175", "66", "66", "264", "52", "110", "175", "215",
"113", "335", "110", "110", "95", "62", "123", "123", "180",
"180", "180", "175", "91", "65", "97", "105", "109"
), drat = c(
"3.15",
"2.93", "3.73", "3.23", "3.85", "2.76", "3.21", "3.62", "4.08",
"4.08", "4.22", "4.93", "3.08", "3.15", "3", "3.77", "3.54",
"3.9", "3.9", "3.92", "3.69", "3.92", "3.92", "3.07", "3.07",
"3.07", "3.08", "4.43", "4.22", "3.7", "2.76", "4.11"
), wt = c(
"3.435",
"5.25", "3.84", "5.345", "2.32", "3.52", "3.57", "2.77",
"2.2", "1.935", "3.17", "1.615", "3.215", "3.44", "5.424",
"1.513", "3.57", "2.62", "2.875", "3.15", "3.19", "3.44",
"3.44", "4.07", "3.73", "3.78", "3.845", "2.14", "1.835",
"2.465", "3.46", "2.78"
), qsec = c(
"17.3", "17.98", "15.41",
"17.42", "18.61", "16.87", "15.84", "15.5", "19.47", "18.9",
"14.5", "18.52", "19.44", "17.02", "17.82", "16.9", "14.6",
"16.46", "17.02", "22.9", "20", "18.3", "18.9", "17.4", "17.6",
"18", "17.05", "16.7", "19.9", "20.01", "20.22", "18.6"
),
vs = c(
"0", "0", "0", "0", "1", "0", "0", "0", "1", "1",
"0", "1", "1", "0", "0", "1", "0", "0", "0", "1", "1", "1",
"1", "0", "0", "0", "0", "0", "1", "1", "1", "1"
), am = c(
"0",
"0", "0", "0", "1", "0", "0", "1", "1", "1", "1", "1", "0",
"0", "0", "1", "1", "1", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "1", "1", "0", "0", "1"
), gear = c(
"3", "3", "3",
"3", "4", "3", "3", "5", "4", "4", "5", "4", "3", "3", "3",
"5", "5", "4", "4", "4", "4", "4", "4", "3", "3", "3", "3",
"5", "4", "3", "3", "4"
), carb = c(
"2", "4", "4", "4", "1",
"2", "4", "6", "1", "1", "4", "2", "1", "2", "4", "2", "8",
"4", "4", "2", "2", "4", "4", "3", "3", "3", "2", "2", "1",
"1", "1", "2"
), color_available___red = c(
"1", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0"
), color_available___green = c(
"1",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), color_available___blue = c(
"1",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), color_available___black = c(
"0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), motor_trend_cars_complete = c(
"1",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), letter_group___a = c(
"1",
"0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "1", "1", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), letter_group___b = c(
"1",
"0", "0", "1", "1", "0", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "1", "1", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), letter_group___c = c(
"0",
"0", "1", "1", "1", "0", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), choice = c(
"choice2",
"", "choice1", "choice1", "", "", "choice1", "", "", "",
"", "", "", "", "", "", "", "", "", "choice2", "", "", "",
"", "", "", "", "", "", "", "", ""
), grouping_complete = c(
"2",
"0", "2", "2", "0", "0", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
)
), row.names = c(
1L, 5L,
6L, 9L, 11L, 12L, 13L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 28L, 29L, 30L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
42L, 43L, 44L, 45L
), class = "data.frame"), sale = structure(list(
row = c(
"AMC Javelin", "AMC Javelin", "AMC Javelin", "Camaro Z28",
"Camaro Z28", "Chrysler Imperial", "Duster 360", "Duster 360",
"Duster 360", "Duster 360", "Merc 230", "Merc 230", "Merc 230"
), redcap_repeat_instrument = c(
"sale", "sale", "sale", "sale",
"sale", "sale", "sale", "sale", "sale", "sale", "sale", "sale",
"sale"
), redcap_repeat_instance = c(
"1", "2", "3", "1", "2",
"1", "1", "2", "3", "4", "1", "2", "3"
), price = c(
"12000.50",
"13750.77", "15004.57", "7800.00", "8000.00", "7500.00",
"8756.40", "6800.88", "8888.88", "970.00", "7800.98", "7954.00",
"6800.55"
), color = c(
"1", "3", "2", "2", "3", "1", "4",
"2", "1", "4", "2", "1", "3"
), customer = c(
"Bob", "Sue",
"Kim", "Janice", "Tim", "Jim", "Sarah", "Pablo", "Erica",
"Juan", "Ted", "Quentin", "Sharon"
), sale_complete = c(
"0",
"2", "0", "2", "0", "2", "1", "0", "0", "0", "0", "0", "2"
)
), row.names = c(
2L, 3L, 4L, 7L, 8L, 10L, 14L, 15L, 16L,
17L, 31L, 32L, 33L
), class = "data.frame"))
)
}) })

View File

@ -13,7 +13,174 @@ redcap_output_csv1 <- REDCap_split(records, metadata)
# Test that basic CSV export matches reference ------------------------------ # Test that basic CSV export matches reference ------------------------------
test_that("CSV export matches reference", { test_that("CSV export matches reference", {
expect_known_hash(redcap_output_csv1, "cb5074a06e1abcf659d60be1016965d2") # expect_known_hash(redcap_output_csv1, "cb5074a06e1abcf659d60be1016965d2")
# dput(redcap_output_csv1)
expect_identical(
redcap_output_csv1,
list(
structure(list(
row = structure(1:32, levels = c(
"AMC Javelin",
"Cadillac Fleetwood", "Camaro Z28", "Chrysler Imperial", "Datsun 710",
"Dodge Challenger", "Duster 360", "Ferrari Dino", "Fiat 128",
"Fiat X1-9", "Ford Pantera L", "Honda Civic", "Hornet 4 Drive",
"Hornet Sportabout", "Lincoln Continental", "Lotus Europa", "Maserati Bora",
"Mazda RX4", "Mazda RX4 Wag", "Merc 230", "Merc 240D", "Merc 280",
"Merc 280C", "Merc 450SE", "Merc 450SL", "Merc 450SLC", "Pontiac Firebird",
"Porsche 914-2", "Toyota Corolla", "Toyota Corona", "Valiant",
"Volvo 142E"
), class = "factor"), mpg = c(
15.2, 10.4, 13.3, 14.7,
22.8, 15.5, 14.3, 19.7, 32.4, 27.3, 15.8, 30.4, 21.4, 18.7, 10.4,
30.4, 15, 21, 21, 22.8, 24.4, 19.2, 17.8, 16.4, 17.3, 15.2, 19.2,
26, 33.9, 21.5, 18.1, 21.4
), cyl = c(
8L, 8L, 8L, 8L, 4L, 8L,
8L, 6L, 4L, 4L, 8L, 4L, 6L, 8L, 8L, 4L, 8L, 6L, 6L, 4L, 4L, 6L,
6L, 8L, 8L, 8L, 8L, 4L, 4L, 4L, 6L, 4L
), disp = c(
304, 472, 350,
440, 108, 318, 360, 145, 78.7, 79, 351, 75.7, 258, 360, 460,
95.1, 301, 160, 160, 140.8, 146.7, 167.6, 167.6, 275.8, 275.8,
275.8, 400, 120.3, 71.1, 120.1, 225, 121
), hp = c(
150L, 205L,
245L, 230L, 93L, 150L, 245L, 175L, 66L, 66L, 264L, 52L, 110L,
175L, 215L, 113L, 335L, 110L, 110L, 95L, 62L, 123L, 123L, 180L,
180L, 180L, 175L, 91L, 65L, 97L, 105L, 109L
), drat = c(
3.15,
2.93, 3.73, 3.23, 3.85, 2.76, 3.21, 3.62, 4.08, 4.08, 4.22, 4.93,
3.08, 3.15, 3, 3.77, 3.54, 3.9, 3.9, 3.92, 3.69, 3.92, 3.92,
3.07, 3.07, 3.07, 3.08, 4.43, 4.22, 3.7, 2.76, 4.11
), wt = c(
3.435,
5.25, 3.84, 5.345, 2.32, 3.52, 3.57, 2.77, 2.2, 1.935, 3.17,
1.615, 3.215, 3.44, 5.424, 1.513, 3.57, 2.62, 2.875, 3.15, 3.19,
3.44, 3.44, 4.07, 3.73, 3.78, 3.845, 2.14, 1.835, 2.465, 3.46,
2.78
), qsec = c(
17.3, 17.98, 15.41, 17.42, 18.61, 16.87, 15.84,
15.5, 19.47, 18.9, 14.5, 18.52, 19.44, 17.02, 17.82, 16.9, 14.6,
16.46, 17.02, 22.9, 20, 18.3, 18.9, 17.4, 17.6, 18, 17.05, 16.7,
19.9, 20.01, 20.22, 18.6
), vs = c(
0L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L,
0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L
), am = c(
0L, 0L, 0L, 0L, 1L,
0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L
), gear = c(
3L, 3L,
3L, 3L, 4L, 3L, 3L, 5L, 4L, 4L, 5L, 4L, 3L, 3L, 3L, 5L, 5L, 4L,
4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 5L, 4L, 3L, 3L, 4L
), carb = c(
2L,
4L, 4L, 4L, 1L, 2L, 4L, 6L, 1L, 1L, 4L, 2L, 1L, 2L, 4L, 2L, 8L,
4L, 4L, 2L, 2L, 4L, 4L, 3L, 3L, 3L, 2L, 2L, 1L, 1L, 1L, 2L
),
color_available___red = c(
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), color_available___green = c(
1L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L
), color_available___blue = c(
1L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), color_available___black = c(
0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L
), motor_trend_cars_complete = c(
1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), letter_group___a = c(
1L,
0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L
), letter_group___b = c(
1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), letter_group___c = c(
0L,
0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L
), choice = structure(c(
3L, 1L, 2L, 2L, 1L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), levels = c(
"", "choice1",
"choice2"
), class = "factor"), grouping_complete = c(
2L,
0L, 2L, 2L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L
)
), row.names = c(
1L, 5L, 6L, 9L, 11L, 12L, 13L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 34L, 35L,
36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L
), class = "data.frame"),
sale = structure(list(
row = structure(c(
1L, 1L, 1L, 3L, 3L,
4L, 7L, 7L, 7L, 7L, 20L, 20L, 20L
), levels = c(
"AMC Javelin",
"Cadillac Fleetwood", "Camaro Z28", "Chrysler Imperial",
"Datsun 710", "Dodge Challenger", "Duster 360", "Ferrari Dino",
"Fiat 128", "Fiat X1-9", "Ford Pantera L", "Honda Civic",
"Hornet 4 Drive", "Hornet Sportabout", "Lincoln Continental",
"Lotus Europa", "Maserati Bora", "Mazda RX4", "Mazda RX4 Wag",
"Merc 230", "Merc 240D", "Merc 280", "Merc 280C", "Merc 450SE",
"Merc 450SL", "Merc 450SLC", "Pontiac Firebird", "Porsche 914-2",
"Toyota Corolla", "Toyota Corona", "Valiant", "Volvo 142E"
), class = "factor"), redcap_repeat_instrument = c(
"sale",
"sale", "sale", "sale", "sale", "sale", "sale", "sale", "sale",
"sale", "sale", "sale", "sale"
), redcap_repeat_instance = c(
1L,
2L, 3L, 1L, 2L, 1L, 1L, 2L, 3L, 4L, 1L, 2L, 3L
), price = c(
12000.5,
13750.77, 15004.57, 7800, 8000, 7500, 8756.4, 6800.88, 8888.88,
970, 7800.98, 7954, 6800.55
), color = c(
1L, 3L, 2L, 2L, 3L,
1L, 4L, 2L, 1L, 4L, 2L, 1L, 3L
), customer = structure(c(
2L,
12L, 7L, 4L, 14L, 5L, 10L, 8L, 3L, 6L, 13L, 9L, 11L
), levels = c(
"",
"Bob", "Erica", "Janice", "Jim", "Juan", "Kim", "Pablo",
"Quentin", "Sarah", "Sharon", "Sue", "Ted", "Tim"
), class = "factor"),
sale_complete = c(
0L, 2L, 0L, 2L, 0L, 2L, 1L, 0L, 0L,
0L, 0L, 0L, 2L
)
), row.names = c(
2L, 3L, 4L, 7L, 8L, 10L,
14L, 15L, 16L, 17L, 31L, 32L, 33L
), class = "data.frame")
)
)
}) })
# Test that REDCap_split can handle a focused dataset # Test that REDCap_split can handle a focused dataset
@ -41,7 +208,345 @@ if (requireNamespace("Hmisc", quietly = TRUE)) {
redcap_output_csv2 <- redcap_output_csv2 <-
REDCap_split(REDCap_process_csv(records), metadata) REDCap_split(REDCap_process_csv(records), metadata)
expect_known_hash(redcap_output_csv2, "578dc054e59ec92a21e950042e08ee37") # expect_known_hash(redcap_output_csv2, "578dc054e59ec92a21e950042e08ee37")
# dput(redcap_output_csv2)
expect_identical(
redcap_output_csv2,
list(structure(list(
row = structure(1:32, levels = c(
"AMC Javelin",
"Cadillac Fleetwood", "Camaro Z28", "Chrysler Imperial", "Datsun 710",
"Dodge Challenger", "Duster 360", "Ferrari Dino", "Fiat 128",
"Fiat X1-9", "Ford Pantera L", "Honda Civic", "Hornet 4 Drive",
"Hornet Sportabout", "Lincoln Continental", "Lotus Europa", "Maserati Bora",
"Mazda RX4", "Mazda RX4 Wag", "Merc 230", "Merc 240D", "Merc 280",
"Merc 280C", "Merc 450SE", "Merc 450SL", "Merc 450SLC", "Pontiac Firebird",
"Porsche 914-2", "Toyota Corolla", "Toyota Corona", "Valiant",
"Volvo 142E"
), class = c("labelled", "factor"), label = "Name"),
mpg = structure(c(
15.2, 10.4, 13.3, 14.7, 22.8, 15.5, 14.3,
19.7, 32.4, 27.3, 15.8, 30.4, 21.4, 18.7, 10.4, 30.4, 15,
21, 21, 22.8, 24.4, 19.2, 17.8, 16.4, 17.3, 15.2, 19.2, 26,
33.9, 21.5, 18.1, 21.4
), label = "Miles/(US) gallon", class = c(
"labelled",
"numeric"
)), cyl = structure(c(
8L, 8L, 8L, 8L, 4L, 8L, 8L,
6L, 4L, 4L, 8L, 4L, 6L, 8L, 8L, 4L, 8L, 6L, 6L, 4L, 4L, 6L,
6L, 8L, 8L, 8L, 8L, 4L, 4L, 4L, 6L, 4L
), label = "Number of cylinders", class = c(
"labelled",
"integer"
)), disp = structure(c(
304, 472, 350, 440, 108,
318, 360, 145, 78.7, 79, 351, 75.7, 258, 360, 460, 95.1,
301, 160, 160, 140.8, 146.7, 167.6, 167.6, 275.8, 275.8,
275.8, 400, 120.3, 71.1, 120.1, 225, 121
), label = "Displacement", class = c(
"labelled",
"numeric"
)), hp = structure(c(
150L, 205L, 245L, 230L, 93L,
150L, 245L, 175L, 66L, 66L, 264L, 52L, 110L, 175L, 215L,
113L, 335L, 110L, 110L, 95L, 62L, 123L, 123L, 180L, 180L,
180L, 175L, 91L, 65L, 97L, 105L, 109L
), label = "Gross horsepower", class = c(
"labelled",
"integer"
)), drat = structure(c(
3.15, 2.93, 3.73, 3.23, 3.85,
2.76, 3.21, 3.62, 4.08, 4.08, 4.22, 4.93, 3.08, 3.15, 3,
3.77, 3.54, 3.9, 3.9, 3.92, 3.69, 3.92, 3.92, 3.07, 3.07,
3.07, 3.08, 4.43, 4.22, 3.7, 2.76, 4.11
), label = "Rear axle ratio", class = c(
"labelled",
"numeric"
)), wt = structure(c(
3.435, 5.25, 3.84, 5.345, 2.32,
3.52, 3.57, 2.77, 2.2, 1.935, 3.17, 1.615, 3.215, 3.44, 5.424,
1.513, 3.57, 2.62, 2.875, 3.15, 3.19, 3.44, 3.44, 4.07, 3.73,
3.78, 3.845, 2.14, 1.835, 2.465, 3.46, 2.78
), label = "Weight", class = c(
"labelled",
"numeric"
)), qsec = structure(c(
17.3, 17.98, 15.41, 17.42,
18.61, 16.87, 15.84, 15.5, 19.47, 18.9, 14.5, 18.52, 19.44,
17.02, 17.82, 16.9, 14.6, 16.46, 17.02, 22.9, 20, 18.3, 18.9,
17.4, 17.6, 18, 17.05, 16.7, 19.9, 20.01, 20.22, 18.6
), label = "1/4 mile time", class = c(
"labelled",
"numeric"
)), vs = structure(c(
0L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L,
1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L
), label = "V engine?", class = c(
"labelled",
"integer"
)), am = structure(c(
0L, 0L, 0L, 0L, 1L, 0L, 0L,
1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L
), label = "Transmission", class = c(
"labelled",
"integer"
)), gear = structure(c(
3L, 3L, 3L, 3L, 4L, 3L, 3L,
5L, 4L, 4L, 5L, 4L, 3L, 3L, 3L, 5L, 5L, 4L, 4L, 4L, 4L, 4L,
4L, 3L, 3L, 3L, 3L, 5L, 4L, 3L, 3L, 4L
), label = "Number of forward gears", class = c(
"labelled",
"integer"
)), carb = structure(c(
2L, 4L, 4L, 4L, 1L, 2L, 4L,
6L, 1L, 1L, 4L, 2L, 1L, 2L, 4L, 2L, 8L, 4L, 4L, 2L, 2L, 4L,
4L, 3L, 3L, 3L, 2L, 2L, 1L, 1L, 1L, 2L
), label = "Number of carburetors", class = c(
"labelled",
"integer"
)), color_available___red = structure(c(
1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), label = "Colors Available (choice<-Red)", class = c(
"labelled",
"integer"
)), color_available___green = structure(c(
1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), label = "Colors Available (choice<-Green)", class = c(
"labelled",
"integer"
)), color_available___blue = structure(c(
1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), label = "Colors Available (choice<-Blue)", class = c(
"labelled",
"integer"
)), color_available___black = structure(c(
0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), label = "Colors Available (choice<-Black)", class = c(
"labelled",
"integer"
)), motor_trend_cars_complete = structure(c(
1L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L
), label = "Complete?", class = c("labelled", "integer")), letter_group___a = structure(c(
1L, 0L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), label = "Which group? (choice<-A)", class = c(
"labelled",
"integer"
)), letter_group___b = structure(c(
1L, 0L, 0L, 1L,
1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), label = "Which group? (choice<-B)", class = c(
"labelled",
"integer"
)), letter_group___c = structure(c(
0L, 0L, 1L, 1L,
1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), label = "Which group? (choice<-C)", class = c(
"labelled",
"integer"
)), choice = structure(c(
3L, 1L, 2L, 2L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), levels = c(
"",
"choice1", "choice2"
), class = c("labelled", "factor"), label = "Choose one"),
grouping_complete = structure(c(
2L, 0L, 2L, 2L, 0L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), label = "Complete?", class = c(
"labelled",
"integer"
)), cyl.factor = structure(c(
6L, 6L, 6L, 6L, 2L,
6L, 6L, 4L, 2L, 2L, 6L, 2L, 4L, 6L, 6L, 2L, 6L, 4L, 4L, 2L,
2L, 4L, 4L, 6L, 6L, 6L, 6L, 2L, 2L, 2L, 4L, 2L
), levels = c(
"3",
"4", "5", "6", "7", "8"
), class = "factor"), vs.factor = structure(c(
2L,
2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L
), levels = c("Yes", "No"), class = "factor"), am.factor = structure(c(
1L,
1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,
2L
), levels = c("Automatic", "Manual"), class = "factor"),
gear.factor = structure(c(
1L, 1L, 1L, 1L, 2L, 1L, 1L, 3L,
2L, 2L, 3L, 2L, 1L, 1L, 1L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 3L, 2L, 1L, 1L, 2L
), levels = c(
"3", "4",
"5"
), class = "factor"), carb.factor = structure(c(
2L, 4L,
4L, 4L, 1L, 2L, 4L, 6L, 1L, 1L, 4L, 2L, 1L, 2L, 4L, 2L, 8L,
4L, 4L, 2L, 2L, 4L, 4L, 3L, 3L, 3L, 2L, 2L, 1L, 1L, 1L, 2L
), levels = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "factor"),
color_available___red.factor = structure(c(
2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), levels = c(
"Unchecked",
"Checked"
), class = "factor"), color_available___green.factor = structure(c(
2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L
), levels = c("Unchecked", "Checked"), class = "factor"),
color_available___blue.factor = structure(c(
2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), levels = c(
"Unchecked",
"Checked"
), class = "factor"), color_available___black.factor = structure(c(
1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L
), levels = c("Unchecked", "Checked"), class = "factor"),
motor_trend_cars_complete.factor = structure(c(
2L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), levels = c(
"Incomplete",
"Unverified", "Complete"
), class = "factor"), letter_group___a.factor = structure(c(
2L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L
), levels = c("Unchecked", "Checked"), class = "factor"),
letter_group___b.factor = structure(c(
2L, 1L, 1L, 2L, 2L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), levels = c(
"Unchecked",
"Checked"
), class = "factor"), letter_group___c.factor = structure(c(
1L,
1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L
), levels = c("Unchecked", "Checked"), class = "factor"),
choice.factor = structure(c(
2L, NA, 1L, 1L, NA, NA, 1L, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2L, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA
), levels = c(
"Choice 1",
"Choice 2"
), class = "factor"), grouping_complete.factor = structure(c(
3L,
1L, 3L, 3L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L
), levels = c("Incomplete", "Unverified", "Complete"), class = "factor")
), row.names = c(
1L,
5L, 6L, 9L, 11L, 12L, 13L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 34L, 35L, 36L, 37L, 38L, 39L, 40L,
41L, 42L, 43L, 44L, 45L
), class = "data.frame"), sale = structure(list(
row = structure(c(
1L, 1L, 1L, 3L, 3L, 4L, 7L, 7L, 7L, 7L,
20L, 20L, 20L
), levels = c(
"AMC Javelin", "Cadillac Fleetwood",
"Camaro Z28", "Chrysler Imperial", "Datsun 710", "Dodge Challenger",
"Duster 360", "Ferrari Dino", "Fiat 128", "Fiat X1-9", "Ford Pantera L",
"Honda Civic", "Hornet 4 Drive", "Hornet Sportabout", "Lincoln Continental",
"Lotus Europa", "Maserati Bora", "Mazda RX4", "Mazda RX4 Wag",
"Merc 230", "Merc 240D", "Merc 280", "Merc 280C", "Merc 450SE",
"Merc 450SL", "Merc 450SLC", "Pontiac Firebird", "Porsche 914-2",
"Toyota Corolla", "Toyota Corona", "Valiant", "Volvo 142E"
), class = c("labelled", "factor"), label = "Name"), redcap_repeat_instrument = c(
"sale",
"sale", "sale", "sale", "sale", "sale", "sale", "sale", "sale",
"sale", "sale", "sale", "sale"
), redcap_repeat_instance = structure(c(
1L,
2L, 3L, 1L, 2L, 1L, 1L, 2L, 3L, 4L, 1L, 2L, 3L
), label = "Repeat Instance", class = c(
"labelled",
"integer"
)), price = structure(c(
12000.5, 13750.77, 15004.57,
7800, 8000, 7500, 8756.4, 6800.88, 8888.88, 970, 7800.98,
7954, 6800.55
), label = "Sale price", class = c(
"labelled",
"numeric"
)), color = structure(c(
1L, 3L, 2L, 2L, 3L, 1L,
4L, 2L, 1L, 4L, 2L, 1L, 3L
), label = "Color", class = c(
"labelled",
"integer"
)), customer = structure(c(
2L, 12L, 7L, 4L, 14L,
5L, 10L, 8L, 3L, 6L, 13L, 9L, 11L
), levels = c(
"", "Bob",
"Erica", "Janice", "Jim", "Juan", "Kim", "Pablo", "Quentin",
"Sarah", "Sharon", "Sue", "Ted", "Tim"
), class = c(
"labelled",
"factor"
), label = "Customer Name"), sale_complete = structure(c(
0L,
2L, 0L, 2L, 0L, 2L, 1L, 0L, 0L, 0L, 0L, 0L, 2L
), label = "Complete?", class = c(
"labelled",
"integer"
)), redcap_repeat_instrument.factor = structure(c(
1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), levels = "Sale", class = "factor"),
color.factor = structure(c(
1L, 3L, 2L, 2L, 3L, 1L, 4L, 2L,
1L, 4L, 2L, 1L, 3L
), levels = c("red", "green", "blue", "black"), class = "factor"), sale_complete.factor = structure(c(
1L,
3L, 1L, 3L, 1L, 3L, 2L, 1L, 1L, 1L, 1L, 1L, 3L
), levels = c(
"Incomplete",
"Unverified", "Complete"
), class = "factor")
), row.names = c(
2L,
3L, 4L, 7L, 8L, 10L, 14L, 15L, 16L, 17L, 31L, 32L, 33L
), class = "data.frame"))
)
}) })
} }

View File

@ -5,7 +5,8 @@ test_that("CSV export matches reference", {
c( c(
records = "WARRIORtestForSoftwa_DATA_2018-06-21_1431.csv", records = "WARRIORtestForSoftwa_DATA_2018-06-21_1431.csv",
metadata = "WARRIORtestForSoftwareUpgrades_DataDictionary_2018-06-21.csv" metadata = "WARRIORtestForSoftwareUpgrades_DataDictionary_2018-06-21.csv"
), get_data_location, FUN.VALUE = "character" ), get_data_location,
FUN.VALUE = "character"
) )
redcap <- lapply(file_paths, read.csv, stringsAsFactors = FALSE) redcap <- lapply(file_paths, read.csv, stringsAsFactors = FALSE)
@ -13,5 +14,182 @@ test_that("CSV export matches reference", {
redcap_output <- with(redcap, REDCap_split(records, metadata)) redcap_output <- with(redcap, REDCap_split(records, metadata))
expect_known_hash(redcap_output, "0934bcb292") # expect_known_hash(redcap_output, "0934bcb292")
expect_identical(redcap_output
,
list(
structure(list(record_id = c(
"806-1", "806-1", "806-2",
"806-2"
), redcap_event_name = c(
"baseline_arm_1", "followup_month_3_arm_1",
"baseline_arm_1", "followup_month_3_arm_1"
), redcap_data_access_group = c(
"uf_test",
"uf_test", "uf_test", "uf_test"
), redcap_survey_identifier = c(
NA,
NA, NA, NA
), signed_consent_1 = c(
"[document]", "", "[document]",
""
), signed_consent_2 = c(NA, NA, NA, NA), signed_consent_3 = c(
NA,
NA, NA, NA
), signed_addendum1 = c(
"[document]", "", "[document]",
""
), signed_addendum2 = c(NA, NA, NA, NA), signed_addendum3 = c(
NA,
NA, NA, NA
), upload_of_signed_icfs_complete = c(2L, NA, 2L, NA), demo_date = c("2018-05-08", "", "2018-05-08", ""), demo_name_first = c(
"Philip",
"", "afadgs", ""
), demo_name_init = c("B", "", "afd", ""), demo_name_last = c(
"Chase",
"", "afdsgfd", ""
), demo_date_birth = c(
"1964-04-09", "", "1977-06-26",
""
), demo_street_ad = c("5959 NW 13th Ave", "", "24325543", ""), demo_city_ad = c("Gainesville", "", "2352453", ""), demo_state_ad = c(
"FL",
"", "fwef", ""
), demo_zip = c(32605L, NA, 32601L, NA), demo_daytime = c(
"(352) 555-0760",
"", "(352) 294-5299", ""
), demo_email = c(
"bobsyouruncle@example.org",
"", "", ""
), demo_ethnic = c(2L, NA, 2L, NA), demo_racial = c(
5L,
NA, 89L, NA
), demo_racial_oth = c(NA, NA, NA, NA), demo_military_mrn = c(
2L,
NA, NA, NA
), demo_ssn = c("111-22-3333", "", "123-45-6789", ""), demographics_complete = c(2L, NA, 2L, NA), elig_icf = c(
1L,
NA, 1L, NA
), elig_ischem = c(1L, NA, 1L, NA), elig_signs___1 = c(
1L,
NA, 0L, NA
), elig_signs___2 = c(0L, NA, 1L, NA), elig_signs___3 = c(
0L,
NA, 0L, NA
), elig_signs___4 = c(0L, NA, 0L, NA), elig_card_cath = c(
1L,
NA, 0L, NA
), elig_card_cath_details = c(1L, NA, NA, NA), elig_cath_disease_severity = c(
NA,
NA, NA, NA
), elig_cath_vessel = c(NA, NA, NA, NA), elig_ejection_fraction = c(
60L,
NA, NA, NA
), elig_cath_ffr = c(1L, NA, NA, NA), elig_ccta = c(
1L,
NA, 0L, NA
), elig_card_cath_details_2 = c(1L, NA, NA, NA), elig_cath_disease_severity_2 = c(
NA,
NA, NA, NA
), elig_ejection_fraction_2 = c(60L, NA, NA, NA), elig_cta_score = c(
24L,
NA, NA, NA
), elig_nocom_med = c(0L, NA, 0L, NA), elig_ischemia_dilated = c(
0L,
NA, 0L, NA
), elig_doc_acs = c(0L, NA, 0L, NA), elig_lvef = c(
0L,
NA, 0L, NA
), elig_nyha_class = c(0L, NA, 0L, NA), elig_hos_hfref = c(
0L,
NA, 0L, NA
), elig_stroke = c(0L, NA, 0L, NA), elig_carnial_hemo = c(
0L,
NA, 0L, NA
), elig_renal = c(0L, NA, 0L, NA), elig_valvular = c(
0L,
NA, 0L, NA
), elig_life_expect = c(0L, NA, 0L, NA), elig_enroll_clinic = c(
0L,
NA, 0L, NA
), elig_intol_ace = c(0L, NA, 0L, NA), elig_intol_arb = c(
0L,
NA, 0L, NA
), elig_intol_statin = c(0L, NA, 0L, NA), elig_intol_pcsk = c(
NA,
NA, NA, NA
), elig_preg = c(0L, NA, 0L, NA), elig_liver_dis = c(
0L,
NA, 0L, NA
), elig_hist_rhab = c(0L, NA, 0L, NA), elig_high_dose = c(
0L,
NA, 0L, NA
), elig_study_yes = c(1L, NA, 1L, NA), elig_date = c(
"2018-05-08",
"", "2018-05-08", ""
), elig_study_no = c(NA, NA, NA, NA), eligibility_complete = c(
2L,
NA, 2L, NA
)), row.names = c(1L, 2L, 7L, 8L), class = "data.frame"),
informed_consent = structure(list(record_id = c(
"806-1",
"806-2"
), redcap_event_name = c("baseline_arm_1", "baseline_arm_1"), redcap_repeat_instrument = c("informed_consent", "informed_consent"), redcap_repeat_instance = c(1L, 1L), redcap_data_access_group = c(
"uf_test",
"uf_test"
), redcap_survey_identifier = c(NA, NA)), row.names = c(
3L,
9L
), class = "data.frame"), informed_consent_and_addendum = structure(list(
record_id = c("806-1", "806-1", "806-1", "806-2"), redcap_event_name = c(
"baseline_arm_1",
"baseline_arm_1", "baseline_arm_1", "baseline_arm_1"
),
redcap_repeat_instrument = c(
"informed_consent_and_addendum",
"informed_consent_and_addendum", "informed_consent_and_addendum",
"informed_consent_and_addendum"
), redcap_repeat_instance = c(
1L,
2L, 3L, 1L
), redcap_data_access_group = c(
"uf_test",
"uf_test", "uf_test", "uf_test"
), redcap_survey_identifier = c(
NA,
NA, NA, NA
), informed_consent_and_addendum_timestamp = c(
"2018-05-08 21:15:12",
"", "", "2018-05-08 21:02:39"
), icf_first_name = c(
"Philip",
"Bobs", "Bobs", "test"
), icf_last_name = c(
"Chase", "Youruncle",
"Youruncle", "test"
), icf_date = c(
"2018-05-08", "2018-06-21",
"2018-06-21", "2018-05-08"
), icf_sign = c(
"[document]",
"[document]", "[document]", "[document]"
), icf_consenter_name = c(
"Philip B Chase",
"Yo Mama", "zsdf", "taryn"
), icf_consentee_info = c(
"UF",
"Anywhere she wants", "DF", "stoffs"
), icf_consentee_sign = c(
"[document]",
"[document]", "[document]", "[document]"
), icf_consentee_date = c(
"2018-05-08",
"2018-06-21", "2018-06-21", "2018-05-08"
), informed_consent_and_addendum_complete = c(
2L,
2L, 2L, 2L
)
), row.names = c(4L, 5L, 6L, 10L), class = "data.frame")
)
)
}) })

View File

@ -8,23 +8,360 @@ metadata <-
records <- records <-
jsonlite::fromJSON(get_data_location("ExampleProject_records.json")) jsonlite::fromJSON(get_data_location("ExampleProject_records.json"))
ref_hash <- "2c8b6531597182af1248f92124161e0c" # ref_hash <- "2c8b6531597182af1248f92124161e0c"
# Tests ------------------------------------------------------------------- # Tests -------------------------------------------------------------------
test_that("Will not use a repeating instrument name for primary table", { test_that("Will not use a repeating instrument name for primary table", {
# local_edition(3)
#
expect_warning(
REDCap_split(records, metadata, "sale"),
"primary table"
)
redcap_output_json1 <- redcap_output_json1 <-
expect_warning(REDCap_split(records, metadata, "sale"), suppressWarnings(REDCap_split(records, metadata, "sale"))
"primary table")
expect_known_hash(redcap_output_json1, ref_hash) # dput(redcap_output_json1)
expect_identical(
redcap_output_json1,
list(structure(list(
row = c(
"AMC Javelin", "Cadillac Fleetwood",
"Camaro Z28", "Chrysler Imperial", "Datsun 710", "Dodge Challenger",
"Duster 360", "Ferrari Dino", "Fiat 128", "Fiat X1-9", "Ford Pantera L",
"Honda Civic", "Hornet 4 Drive", "Hornet Sportabout", "Lincoln Continental",
"Lotus Europa", "Maserati Bora", "Mazda RX4", "Mazda RX4 Wag",
"Merc 230", "Merc 240D", "Merc 280", "Merc 280C", "Merc 450SE",
"Merc 450SL", "Merc 450SLC", "Pontiac Firebird", "Porsche 914-2",
"Toyota Corolla", "Toyota Corona", "Valiant", "Volvo 142E"
),
mpg = c(
"15.2", "10.4", "13.3", "14.7", "22.8", "15.5", "14.3",
"19.7", "32.4", "27.3", "15.8", "30.4", "21.4", "18.7", "10.4",
"30.4", "15", "21", "21", "22.8", "24.4", "19.2", "17.8",
"16.4", "17.3", "15.2", "19.2", "26", "33.9", "21.5", "18.1",
"21.4"
), cyl = c(
"8", "8", "8", "8", "4", "8", "8", "6",
"4", "4", "8", "4", "6", "8", "8", "4", "8", "6", "6", "4",
"4", "6", "6", "8", "8", "8", "8", "4", "4", "4", "6", "4"
), disp = c(
"304", "472", "350", "440", "108", "318", "360",
"145", "78.7", "79", "351", "75.7", "258", "360", "460",
"95.1", "301", "160", "160", "140.8", "146.7", "167.6", "167.6",
"275.8", "275.8", "275.8", "400", "120.3", "71.1", "120.1",
"225", "121"
), hp = c(
"150", "205", "245", "230", "93", "150",
"245", "175", "66", "66", "264", "52", "110", "175", "215",
"113", "335", "110", "110", "95", "62", "123", "123", "180",
"180", "180", "175", "91", "65", "97", "105", "109"
), drat = c(
"3.15",
"2.93", "3.73", "3.23", "3.85", "2.76", "3.21", "3.62", "4.08",
"4.08", "4.22", "4.93", "3.08", "3.15", "3", "3.77", "3.54",
"3.9", "3.9", "3.92", "3.69", "3.92", "3.92", "3.07", "3.07",
"3.07", "3.08", "4.43", "4.22", "3.7", "2.76", "4.11"
), wt = c(
"3.435",
"5.25", "3.84", "5.345", "2.32", "3.52", "3.57", "2.77",
"2.2", "1.935", "3.17", "1.615", "3.215", "3.44", "5.424",
"1.513", "3.57", "2.62", "2.875", "3.15", "3.19", "3.44",
"3.44", "4.07", "3.73", "3.78", "3.845", "2.14", "1.835",
"2.465", "3.46", "2.78"
), qsec = c(
"17.3", "17.98", "15.41",
"17.42", "18.61", "16.87", "15.84", "15.5", "19.47", "18.9",
"14.5", "18.52", "19.44", "17.02", "17.82", "16.9", "14.6",
"16.46", "17.02", "22.9", "20", "18.3", "18.9", "17.4", "17.6",
"18", "17.05", "16.7", "19.9", "20.01", "20.22", "18.6"
),
vs = c(
"0", "0", "0", "0", "1", "0", "0", "0", "1", "1",
"0", "1", "1", "0", "0", "1", "0", "0", "0", "1", "1", "1",
"1", "0", "0", "0", "0", "0", "1", "1", "1", "1"
), am = c(
"0",
"0", "0", "0", "1", "0", "0", "1", "1", "1", "1", "1", "0",
"0", "0", "1", "1", "1", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "1", "1", "0", "0", "1"
), gear = c(
"3", "3", "3",
"3", "4", "3", "3", "5", "4", "4", "5", "4", "3", "3", "3",
"5", "5", "4", "4", "4", "4", "4", "4", "3", "3", "3", "3",
"5", "4", "3", "3", "4"
), carb = c(
"2", "4", "4", "4", "1",
"2", "4", "6", "1", "1", "4", "2", "1", "2", "4", "2", "8",
"4", "4", "2", "2", "4", "4", "3", "3", "3", "2", "2", "1",
"1", "1", "2"
), color_available___red = c(
"1", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0"
), color_available___green = c(
"1",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), color_available___blue = c(
"1",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), color_available___black = c(
"0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), motor_trend_cars_complete = c(
"1",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), letter_group___a = c(
"1",
"0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "1", "1", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), letter_group___b = c(
"1",
"0", "0", "1", "1", "0", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "1", "1", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), letter_group___c = c(
"0",
"0", "1", "1", "1", "0", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), choice = c(
"choice2",
"", "choice1", "choice1", "", "", "choice1", "", "", "",
"", "", "", "", "", "", "", "", "", "choice2", "", "", "",
"", "", "", "", "", "", "", "", ""
), grouping_complete = c(
"2",
"0", "2", "2", "0", "0", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
)
), row.names = c(
1L, 5L,
6L, 9L, 11L, 12L, 13L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 28L, 29L, 30L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
42L, 43L, 44L, 45L
), class = "data.frame"), sale = structure(list(
row = c(
"AMC Javelin", "AMC Javelin", "AMC Javelin", "Camaro Z28",
"Camaro Z28", "Chrysler Imperial", "Duster 360", "Duster 360",
"Duster 360", "Duster 360", "Merc 230", "Merc 230", "Merc 230"
), redcap_repeat_instrument = c(
"sale", "sale", "sale", "sale",
"sale", "sale", "sale", "sale", "sale", "sale", "sale", "sale",
"sale"
), redcap_repeat_instance = c(
"1", "2", "3", "1", "2",
"1", "1", "2", "3", "4", "1", "2", "3"
), price = c(
"12000.50",
"13750.77", "15004.57", "7800.00", "8000.00", "7500.00",
"8756.40", "6800.88", "8888.88", "970.00", "7800.98", "7954.00",
"6800.55"
), color = c(
"1", "3", "2", "2", "3", "1", "4",
"2", "1", "4", "2", "1", "3"
), customer = c(
"Bob", "Sue",
"Kim", "Janice", "Tim", "Jim", "Sarah", "Pablo", "Erica",
"Juan", "Ted", "Quentin", "Sharon"
), sale_complete = c(
"0",
"2", "0", "2", "0", "2", "1", "0", "0", "0", "0", "0", "2"
)
), row.names = c(
2L, 3L, 4L, 7L, 8L, 10L, 14L, 15L, 16L,
17L, 31L, 32L, 33L
), class = "data.frame"))
)
# expect_snapshot(redcap_output_json1)
# expect_known_hash(redcap_output_json1, ref_hash)
}) })
test_that("Names are set correctly and output is identical", { test_that("Names are set correctly and output is identical", {
# local_edition(3)
redcap_output_json2 <- REDCap_split(records, metadata, "main") redcap_output_json2 <- REDCap_split(records, metadata, "main")
expect_identical(names(redcap_output_json2), c("main", "sale")) expect_identical(names(redcap_output_json2), c("main", "sale"))
expect_known_hash(setNames(redcap_output_json2, c("", "sale")), ref_hash) # expect_known_hash(setNames(redcap_output_json2, c("", "sale")), ref_hash)
# dput(redcap_output_json2)
expect_identical(
redcap_output_json2,
list(main = structure(list(
row = c(
"AMC Javelin", "Cadillac Fleetwood",
"Camaro Z28", "Chrysler Imperial", "Datsun 710", "Dodge Challenger",
"Duster 360", "Ferrari Dino", "Fiat 128", "Fiat X1-9", "Ford Pantera L",
"Honda Civic", "Hornet 4 Drive", "Hornet Sportabout", "Lincoln Continental",
"Lotus Europa", "Maserati Bora", "Mazda RX4", "Mazda RX4 Wag",
"Merc 230", "Merc 240D", "Merc 280", "Merc 280C", "Merc 450SE",
"Merc 450SL", "Merc 450SLC", "Pontiac Firebird", "Porsche 914-2",
"Toyota Corolla", "Toyota Corona", "Valiant", "Volvo 142E"
),
mpg = c(
"15.2", "10.4", "13.3", "14.7", "22.8", "15.5", "14.3",
"19.7", "32.4", "27.3", "15.8", "30.4", "21.4", "18.7", "10.4",
"30.4", "15", "21", "21", "22.8", "24.4", "19.2", "17.8",
"16.4", "17.3", "15.2", "19.2", "26", "33.9", "21.5", "18.1",
"21.4"
), cyl = c(
"8", "8", "8", "8", "4", "8", "8", "6",
"4", "4", "8", "4", "6", "8", "8", "4", "8", "6", "6", "4",
"4", "6", "6", "8", "8", "8", "8", "4", "4", "4", "6", "4"
), disp = c(
"304", "472", "350", "440", "108", "318", "360",
"145", "78.7", "79", "351", "75.7", "258", "360", "460",
"95.1", "301", "160", "160", "140.8", "146.7", "167.6", "167.6",
"275.8", "275.8", "275.8", "400", "120.3", "71.1", "120.1",
"225", "121"
), hp = c(
"150", "205", "245", "230", "93", "150",
"245", "175", "66", "66", "264", "52", "110", "175", "215",
"113", "335", "110", "110", "95", "62", "123", "123", "180",
"180", "180", "175", "91", "65", "97", "105", "109"
), drat = c(
"3.15",
"2.93", "3.73", "3.23", "3.85", "2.76", "3.21", "3.62", "4.08",
"4.08", "4.22", "4.93", "3.08", "3.15", "3", "3.77", "3.54",
"3.9", "3.9", "3.92", "3.69", "3.92", "3.92", "3.07", "3.07",
"3.07", "3.08", "4.43", "4.22", "3.7", "2.76", "4.11"
), wt = c(
"3.435",
"5.25", "3.84", "5.345", "2.32", "3.52", "3.57", "2.77",
"2.2", "1.935", "3.17", "1.615", "3.215", "3.44", "5.424",
"1.513", "3.57", "2.62", "2.875", "3.15", "3.19", "3.44",
"3.44", "4.07", "3.73", "3.78", "3.845", "2.14", "1.835",
"2.465", "3.46", "2.78"
), qsec = c(
"17.3", "17.98", "15.41",
"17.42", "18.61", "16.87", "15.84", "15.5", "19.47", "18.9",
"14.5", "18.52", "19.44", "17.02", "17.82", "16.9", "14.6",
"16.46", "17.02", "22.9", "20", "18.3", "18.9", "17.4", "17.6",
"18", "17.05", "16.7", "19.9", "20.01", "20.22", "18.6"
),
vs = c(
"0", "0", "0", "0", "1", "0", "0", "0", "1", "1",
"0", "1", "1", "0", "0", "1", "0", "0", "0", "1", "1", "1",
"1", "0", "0", "0", "0", "0", "1", "1", "1", "1"
), am = c(
"0",
"0", "0", "0", "1", "0", "0", "1", "1", "1", "1", "1", "0",
"0", "0", "1", "1", "1", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "1", "1", "0", "0", "1"
), gear = c(
"3", "3", "3",
"3", "4", "3", "3", "5", "4", "4", "5", "4", "3", "3", "3",
"5", "5", "4", "4", "4", "4", "4", "4", "3", "3", "3", "3",
"5", "4", "3", "3", "4"
), carb = c(
"2", "4", "4", "4", "1",
"2", "4", "6", "1", "1", "4", "2", "1", "2", "4", "2", "8",
"4", "4", "2", "2", "4", "4", "3", "3", "3", "2", "2", "1",
"1", "1", "2"
), color_available___red = c(
"1", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0"
), color_available___green = c(
"1",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), color_available___blue = c(
"1",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), color_available___black = c(
"0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), motor_trend_cars_complete = c(
"1",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), letter_group___a = c(
"1",
"0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "1", "1", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), letter_group___b = c(
"1",
"0", "0", "1", "1", "0", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "1", "1", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), letter_group___c = c(
"0",
"0", "1", "1", "1", "0", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
), choice = c(
"choice2",
"", "choice1", "choice1", "", "", "choice1", "", "", "",
"", "", "", "", "", "", "", "", "", "choice2", "", "", "",
"", "", "", "", "", "", "", "", ""
), grouping_complete = c(
"2",
"0", "2", "2", "0", "0", "1", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0"
)
), row.names = c(
1L, 5L,
6L, 9L, 11L, 12L, 13L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 28L, 29L, 30L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
42L, 43L, 44L, 45L
), class = "data.frame"), sale = structure(list(
row = c(
"AMC Javelin", "AMC Javelin", "AMC Javelin", "Camaro Z28",
"Camaro Z28", "Chrysler Imperial", "Duster 360", "Duster 360",
"Duster 360", "Duster 360", "Merc 230", "Merc 230", "Merc 230"
), redcap_repeat_instrument = c(
"sale", "sale", "sale", "sale",
"sale", "sale", "sale", "sale", "sale", "sale", "sale", "sale",
"sale"
), redcap_repeat_instance = c(
"1", "2", "3", "1", "2",
"1", "1", "2", "3", "4", "1", "2", "3"
), price = c(
"12000.50",
"13750.77", "15004.57", "7800.00", "8000.00", "7500.00",
"8756.40", "6800.88", "8888.88", "970.00", "7800.98", "7954.00",
"6800.55"
), color = c(
"1", "3", "2", "2", "3", "1", "4",
"2", "1", "4", "2", "1", "3"
), customer = c(
"Bob", "Sue",
"Kim", "Janice", "Tim", "Jim", "Sarah", "Pablo", "Erica",
"Juan", "Ted", "Quentin", "Sharon"
), sale_complete = c(
"0",
"2", "0", "2", "0", "2", "1", "0", "0", "0", "0", "0", "2"
)
), row.names = c(
2L, 3L, 4L, 7L, 8L, 10L, 14L, 15L, 16L,
17L, 31L, 32L, 33L
), class = "data.frame"))
)
}) })