mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-11-22 13:30:23 +01:00
Cleaning up code for #12
test now compares read_csv and read.csv output directly.
This commit is contained in:
parent
4a06d00a0c
commit
a83221432f
@ -87,11 +87,7 @@ REDCap_split <- function(records,
|
|||||||
|
|
||||||
# Process user input
|
# Process user input
|
||||||
records <- process_user_input(records)
|
records <- process_user_input(records)
|
||||||
metadata <- process_user_input(metadata)
|
metadata <- as.data.frame(process_user_input(metadata)) # See issue #12
|
||||||
|
|
||||||
# Remove "tbl_df" class from metadata, if present, due to difference in
|
|
||||||
# `[.tbl_df` behavior as compared to `[.data.frame` behavior (see issue #12)
|
|
||||||
if(inherits(metadata, "tbl_df")) class(metadata) <- "data.frame"
|
|
||||||
|
|
||||||
# Get the variable names in the dataset
|
# Get the variable names in the dataset
|
||||||
vars_in_data <- names(records)
|
vars_in_data <- names(records)
|
||||||
|
@ -13,10 +13,10 @@ records <- read.csv(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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", {
|
||||||
redcap_output_csv1 <- REDCap_split(records, metadata)
|
|
||||||
|
|
||||||
expect_known_hash(redcap_output_csv1, "f74558d1939c17d9ff0e08a19b956e26")
|
expect_known_hash(redcap_output_csv1, "f74558d1939c17d9ff0e08a19b956e26")
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -29,3 +29,42 @@ if (requireNamespace("Hmisc", quietly = TRUE)) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (requireNamespace("readr", quietly = TRUE)) {
|
||||||
|
|
||||||
|
context("Compatibility with readr")
|
||||||
|
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
if (requireNamespace("readr", quietly = TRUE)) {
|
|
||||||
|
|
||||||
context("Compatibility with readr")
|
|
||||||
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
test_that("Data read in with `readr` will return correct result", {
|
|
||||||
redcap_output_readr <- REDCap_split(records, metadata)
|
|
||||||
expect_known_hash(redcap_output_readr, "bde303d330fba161ca500c10cfabb693")
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user