Merge pull request #14 from SpectrumHealthResearch/issue12

REDCap_split() now compatible with tibbles
This commit is contained in:
kampfsca 2019-09-09 09:39:44 -04:00 committed by GitHub
commit c0c74e67d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 7 deletions

View File

@ -1,6 +1,6 @@
Package: REDCapRITS Package: REDCapRITS
Title: REDCap Repeating Instrument Table Splitter Title: REDCap Repeating Instrument Table Splitter
Version: 0.2.0 Version: 0.2.1
Authors@R: c( Authors@R: c(
person("Paul", "Egeler", email = "paul.egeler@spectrumhealth.org", role = c("aut", "cre")), person("Paul", "Egeler", email = "paul.egeler@spectrumhealth.org", role = c("aut", "cre")),
person("Spectrum Health, Grand Rapids, MI", role = "cph")) person("Spectrum Health, Grand Rapids, MI", role = "cph"))
@ -14,7 +14,8 @@ Suggests:
httr, httr,
jsonlite, jsonlite,
testthat, testthat,
Hmisc Hmisc,
readr
License: GPL-3 License: GPL-3
Encoding: UTF-8 Encoding: UTF-8
LazyData: true LazyData: true

View File

@ -1,4 +1,8 @@
# REDCapRITS 0.2.0 (Release date: 2019-??-??) # REDCapRITS 0.2.1 (Release date: 2019-07-26)
* [bug] Can now accept `"tbl_df"` objects and `NA`s in the `redcap_repeat_instrument` field. (#12)
# REDCapRITS 0.2.0 (Release date: 2019-07-08)
* [feature] User can now separate each form into its own data.frame, regardless if it is a repeating instrument or not. (#10) * [feature] User can now separate each form into its own data.frame, regardless if it is a repeating instrument or not. (#10)
* [bug] Handles auto-generated form timestamp fields. * [bug] Handles auto-generated form timestamp fields.

View File

@ -87,7 +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
# Get the variable names in the dataset # Get the variable names in the dataset
vars_in_data <- names(records) vars_in_data <- names(records)
@ -100,6 +100,15 @@ REDCap_split <- function(records,
stop("There are no repeating instruments in this dataset.") 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 # Standardize variable names for metadata
names(metadata) <- metadata_names names(metadata) <- metadata_names

View File

@ -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)
})
}