mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-19 13:17:30 +02:00
gp with CRAN in sight
This commit is contained in:
parent
20f08c271b
commit
349ff695e1
24 changed files with 338 additions and 157 deletions
|
|
@ -1,12 +1,14 @@
|
|||
|
||||
|
||||
# Set up the path and data -------------------------------------------------
|
||||
metadata <- read.csv(
|
||||
get_data_location("ExampleProject_DataDictionary_2018-06-07.csv"),
|
||||
stringsAsFactors = TRUE
|
||||
)
|
||||
|
||||
records <- read.csv(get_data_location("ExampleProject_DATA_2018-06-07_1129.csv"),
|
||||
stringsAsFactors = TRUE)
|
||||
records <-
|
||||
read.csv(get_data_location("ExampleProject_DATA_2018-06-07_1129.csv"),
|
||||
stringsAsFactors = TRUE)
|
||||
|
||||
redcap_output_csv1 <- REDCap_split(records, metadata)
|
||||
|
||||
|
|
@ -18,16 +20,18 @@ test_that("CSV export matches reference", {
|
|||
# Test that REDCap_split can handle a focused dataset
|
||||
|
||||
records_red <- records[!records$redcap_repeat_instrument == "sale",
|
||||
!names(records) %in% metadata$field_name[metadata$form_name == "sale"] &
|
||||
!names(records) == "sale_complete"]
|
||||
records_red$redcap_repeat_instrument <- as.character(records_red$redcap_repeat_instrument)
|
||||
!names(records) %in%
|
||||
metadata$field_name[metadata$form_name == "sale"] &
|
||||
!names(records) == "sale_complete"]
|
||||
records_red$redcap_repeat_instrument <-
|
||||
as.character(records_red$redcap_repeat_instrument)
|
||||
|
||||
redcap_output_red <- REDCap_split(records_red, metadata)
|
||||
|
||||
|
||||
test_that("REDCap_split handles subset dataset",
|
||||
{
|
||||
testthat::expect_length(redcap_output_red,1)
|
||||
testthat::expect_length(redcap_output_red, 1)
|
||||
})
|
||||
|
||||
|
||||
|
|
@ -37,17 +41,20 @@ if (requireNamespace("Hmisc", quietly = TRUE)) {
|
|||
redcap_output_csv2 <-
|
||||
REDCap_split(REDCap_process_csv(records), metadata)
|
||||
|
||||
expect_known_hash(redcap_output_csv2, "34f82cab35bf8aae47d08cd96f743e6b")
|
||||
expect_known_hash(redcap_output_csv2, "6d8d0462ab2343b848a086ab06b50fe3")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if (requireNamespace("readr", quietly = TRUE)) {
|
||||
context("Compatibility with readr")
|
||||
|
||||
metadata <- readr::read_csv(get_data_location("ExampleProject_DataDictionary_2018-06-07.csv"))
|
||||
metadata <-
|
||||
readr::read_csv(get_data_location(
|
||||
"ExampleProject_DataDictionary_2018-06-07.csv"))
|
||||
|
||||
records <- readr::read_csv(get_data_location("ExampleProject_DATA_2018-06-07_1129.csv"))
|
||||
records <-
|
||||
readr::read_csv(get_data_location(
|
||||
"ExampleProject_DATA_2018-06-07_1129.csv"))
|
||||
|
||||
redcap_output_readr <- REDCap_split(records, metadata)
|
||||
|
||||
|
|
@ -57,11 +64,14 @@ if (requireNamespace("readr", quietly = TRUE)) {
|
|||
lapply(redcap_output_csv1, FUN))
|
||||
}
|
||||
|
||||
test_that("Result of data read in with `readr` will match result with `read.csv`",
|
||||
test_that("Result of data read in with `readr` will
|
||||
match result with `read.csv`",
|
||||
{
|
||||
# The list itself
|
||||
expect_identical(length(redcap_output_readr), length(redcap_output_csv1))
|
||||
expect_identical(names(redcap_output_readr), names(redcap_output_csv1))
|
||||
expect_identical(length(redcap_output_readr),
|
||||
length(redcap_output_csv1))
|
||||
expect_identical(names(redcap_output_readr),
|
||||
names(redcap_output_csv1))
|
||||
|
||||
# Each element of the list
|
||||
expect_matching_elements(names)
|
||||
|
|
@ -69,5 +79,3 @@ if (requireNamespace("readr", quietly = TRUE)) {
|
|||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue