mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-11-22 13:30:23 +01:00
parent
d15c2d35ad
commit
cb253af3ba
@ -14,7 +14,8 @@ Suggests:
|
||||
httr,
|
||||
jsonlite,
|
||||
testthat,
|
||||
Hmisc
|
||||
Hmisc,
|
||||
readr
|
||||
License: GPL-3
|
||||
Encoding: UTF-8
|
||||
LazyData: true
|
||||
|
@ -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
|
||||
|
||||
|
22
R/tests/testthat/test-readr.R
Normal file
22
R/tests/testthat/test-readr.R
Normal 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")
|
||||
})
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user