Closing issue #12

test included
This commit is contained in:
Paul W. Egeler, MS, GStat 2019-07-26 17:26:33 -04:00
parent d15c2d35ad
commit cb253af3ba
3 changed files with 37 additions and 1 deletions

View File

@ -14,7 +14,8 @@ Suggests:
httr,
jsonlite,
testthat,
Hmisc
Hmisc,
readr
License: GPL-3
Encoding: UTF-8
LazyData: true

View File

@ -89,6 +89,10 @@ REDCap_split <- function(records,
records <- process_user_input(records)
metadata <- process_user_input(metadata)
# 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
vars_in_data <- names(records)
@ -100,6 +104,15 @@ REDCap_split <- function(records,
stop("There are no repeating instruments in this dataset.")
}
# Remove NAs from `redcap_repeat_instrument` (see issue #12)
if(any(is.na(records$redcap_repeat_instrument))) {
records$redcap_repeat_instrument <- ifelse(
is.na(records$redcap_repeat_instrument),
"",
as.character(records$redcap_repeat_instrument)
)
}
# Standardize variable names for metadata
names(metadata) <- metadata_names

View File

@ -0,0 +1,22 @@
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")
})
}