mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-19 13:17:30 +02:00
linting
This commit is contained in:
parent
a0730cb41c
commit
9e33057c06
32 changed files with 456 additions and 340 deletions
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
# Set up the path and data -------------------------------------------------
|
||||
metadata <- read.csv(
|
||||
get_data_location("ExampleProject_DataDictionary_2018-06-07.csv"),
|
||||
|
|
@ -8,7 +6,8 @@ metadata <- read.csv(
|
|||
|
||||
records <-
|
||||
read.csv(get_data_location("ExampleProject_DATA_2018-06-07_1129.csv"),
|
||||
stringsAsFactors = TRUE)
|
||||
stringsAsFactors = TRUE
|
||||
)
|
||||
|
||||
redcap_output_csv1 <- REDCap_split(records, metadata)
|
||||
|
||||
|
|
@ -19,20 +18,21 @@ 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 <- 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)
|
||||
|
||||
redcap_output_red <- REDCap_split(records_red, metadata)
|
||||
|
||||
|
||||
test_that("REDCap_split handles subset dataset",
|
||||
{
|
||||
testthat::expect_length(redcap_output_red, 1)
|
||||
})
|
||||
test_that("REDCap_split handles subset dataset", {
|
||||
testthat::expect_length(redcap_output_red, 1)
|
||||
})
|
||||
|
||||
|
||||
# Test that R code enhanced CSV export matches reference --------------------
|
||||
|
|
@ -47,35 +47,40 @@ if (requireNamespace("Hmisc", quietly = TRUE)) {
|
|||
|
||||
|
||||
if (requireNamespace("readr", quietly = TRUE)) {
|
||||
|
||||
metadata <-
|
||||
readr::read_csv(get_data_location(
|
||||
"ExampleProject_DataDictionary_2018-06-07.csv"))
|
||||
"ExampleProject_DataDictionary_2018-06-07.csv"
|
||||
))
|
||||
|
||||
records <-
|
||||
readr::read_csv(get_data_location(
|
||||
"ExampleProject_DATA_2018-06-07_1129.csv"))
|
||||
"ExampleProject_DATA_2018-06-07_1129.csv"
|
||||
))
|
||||
|
||||
redcap_output_readr <- REDCap_split(records, metadata)
|
||||
|
||||
expect_matching_elements <- function(FUN) {
|
||||
FUN <- match.fun(FUN)
|
||||
expect_identical(lapply(redcap_output_readr, FUN),
|
||||
lapply(redcap_output_csv1, FUN))
|
||||
expect_identical(
|
||||
lapply(redcap_output_readr, FUN),
|
||||
lapply(redcap_output_csv1, FUN)
|
||||
)
|
||||
}
|
||||
|
||||
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))
|
||||
|
||||
# Each element of the list
|
||||
expect_matching_elements(names)
|
||||
expect_matching_elements(dim)
|
||||
})
|
||||
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)
|
||||
)
|
||||
|
||||
# Each element of the list
|
||||
expect_matching_elements(names)
|
||||
expect_matching_elements(dim)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue