Skip to content

Commit

Permalink
#11 added quiet = quiet arguement to date and time cleaning steps
Browse files Browse the repository at this point in the history
  • Loading branch information
pgstevenson committed Jul 2, 2021
1 parent 3a1c524 commit 19fc1e9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions R/clean_REDCap.R
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ yesno_vars <- function(d) {
#' @param dict REDCap data dictionary (data frame)
#' @param numeric_date (default FALSE) set to TRUE if MS Excel has _helpfully_ converted to a numeric date
#' @param yesno_to_bool (default FALSE) convert factors with levels `c("Yes", "No")` to logical objects?
#' @param quiet (default FALSE) pass quiet argument to lubridate functions
#'
#' @return cleaned data frame
#'
Expand All @@ -338,7 +339,7 @@ yesno_vars <- function(d) {
#' }
#'
#' @export
clean_REDCap <- function(d, dict, numeric_date = FALSE, yesno_to_bool = FALSE) {
clean_REDCap <- function(d, dict, numeric_date = FALSE, yesno_to_bool = FALSE, quiet = FALSE) {

dict <- dict[dict$`Variable / Field Name` %in% str_replace(names(d), "___\\d+", ""),] # remove items from dictionary that aren't in the dataset

Expand All @@ -356,11 +357,11 @@ clean_REDCap <- function(d, dict, numeric_date = FALSE, yesno_to_bool = FALSE) {
d <- mutate(d, across(dict[grepl("^date.*$", dict$`Text Validation Type OR Show Slider Number`, perl = TRUE),]$`Variable / Field Name`, ~excel_numeric_to_date(as.numeric(.))))
} else {
d <- mutate(d,
across(dict[map_lgl(str_detect(dict$`Text Validation Type OR Show Slider Number`, "^date_"), isTRUE),]$`Variable / Field Name`, ymd),
across(dict[map_lgl(str_detect(dict$`Text Validation Type OR Show Slider Number`, "^datetime_(?!seconds_)"), isTRUE),]$`Variable / Field Name`, ymd_hm),
across(dict[map_lgl(str_detect(dict$`Text Validation Type OR Show Slider Number`, "^datetime_seconds_"), isTRUE),]$`Variable / Field Name`, ymd_hms),
across(dict[map_lgl(str_detect(dict$`Text Validation Type OR Show Slider Number`, "^time$"), isTRUE),]$`Variable / Field Name`, hm),
across(dict[map_lgl(str_detect(dict$`Text Validation Type OR Show Slider Number`, "^time_mm_ss$"), isTRUE),]$`Variable / Field Name`, ms))
across(dict[map_lgl(str_detect(dict$`Text Validation Type OR Show Slider Number`, "^date_"), isTRUE),]$`Variable / Field Name`, ymd, quiet = quiet),
across(dict[map_lgl(str_detect(dict$`Text Validation Type OR Show Slider Number`, "^datetime_(?!seconds_)"), isTRUE),]$`Variable / Field Name`, ymd_hm, quiet = quiet),
across(dict[map_lgl(str_detect(dict$`Text Validation Type OR Show Slider Number`, "^datetime_seconds_"), isTRUE),]$`Variable / Field Name`, ymd_hms, quiet = quiet),
across(dict[map_lgl(str_detect(dict$`Text Validation Type OR Show Slider Number`, "^time$"), isTRUE),]$`Variable / Field Name`, hm, quiet = quiet),
across(dict[map_lgl(str_detect(dict$`Text Validation Type OR Show Slider Number`, "^time_mm_ss$"), isTRUE),]$`Variable / Field Name`, ms, quiet = quiet))
}

if (yesno_to_bool)
Expand Down

0 comments on commit 19fc1e9

Please sign in to comment.