mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-19 13:17:30 +02:00
Increment to v 0.2.0 and closes #10
Form timestamp fields also captured now.
This commit is contained in:
parent
e7be5c1808
commit
d15c2d35ad
6 changed files with 121 additions and 4 deletions
63
R/tests/testthat/test-forms-arg.R
Normal file
63
R/tests/testthat/test-forms-arg.R
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
context("Using the `forms = 'all'` argument")
|
||||
|
||||
# Global variables --------------------------------------------------------
|
||||
|
||||
# Cars
|
||||
metadata <- jsonlite::fromJSON(
|
||||
get_data_location(
|
||||
"ExampleProject_metadata.json"
|
||||
)
|
||||
)
|
||||
|
||||
records <- jsonlite::fromJSON(
|
||||
get_data_location(
|
||||
"ExampleProject_records.json"
|
||||
)
|
||||
)
|
||||
|
||||
redcap_output_json <- REDCap_split(records, metadata, forms = "all")
|
||||
|
||||
# Longitudinal
|
||||
file_paths <- sapply(
|
||||
c(
|
||||
records = "WARRIORtestForSoftwa_DATA_2018-06-21_1431.csv",
|
||||
metadata = "WARRIORtestForSoftwareUpgrades_DataDictionary_2018-06-21.csv"
|
||||
), get_data_location
|
||||
)
|
||||
|
||||
redcap <- lapply(file_paths, read.csv, stringsAsFactors = FALSE)
|
||||
redcap[["metadata"]] <- with(redcap, metadata[metadata[,1] > "",])
|
||||
redcap_output_long <- with(redcap, REDCap_split(records, metadata, forms = "all"))
|
||||
redcap_long_names <- names(redcap[[1]])
|
||||
|
||||
# Tests -------------------------------------------------------------------
|
||||
|
||||
test_that("Each form is an element in the list", {
|
||||
|
||||
expect_length(redcap_output_json, 3L)
|
||||
expect_identical(names(redcap_output_json), c("motor_trend_cars", "grouping", "sale"))
|
||||
|
||||
})
|
||||
|
||||
test_that("All variables land somewhere", {
|
||||
|
||||
expect_true(setequal(names(records), Reduce("union", sapply(redcap_output_json, names))))
|
||||
|
||||
})
|
||||
|
||||
|
||||
test_that("Primary table name is ignored", {
|
||||
expect_identical(
|
||||
REDCap_split(records, metadata, "HELLO", "all"),
|
||||
redcap_output_json
|
||||
)
|
||||
})
|
||||
|
||||
test_that("Supports longitudinal data", {
|
||||
|
||||
# setdiff(redcap_long_names, Reduce("union", sapply(redcap_output_long, names)))
|
||||
## [1] "informed_consent_and_addendum_timestamp"
|
||||
|
||||
expect_true(setequal(redcap_long_names, Reduce("union", sapply(redcap_output_long, names))))
|
||||
|
||||
})
|
||||
|
|
@ -13,5 +13,5 @@ test_that("CSV export matches reference", {
|
|||
redcap_output <- with(redcap, REDCap_split(records, metadata))
|
||||
|
||||
|
||||
expect_known_hash(redcap_output, "dff3a52955")
|
||||
expect_known_hash(redcap_output, "0934bcb292")
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue