Skip to content

Commit

Permalink
Merge pull request IDEMSInternational#5622 from dannyparsons/one-var
Browse files Browse the repository at this point in the history
One var summaries - bug fix for character columns
  • Loading branch information
dannyparsons authored Dec 17, 2019
2 parents b68074e + 8cb3733 commit 51f5bf0
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,19 @@ DataBook$set("public", "summary", function(data_name, columns_to_summarise, summ
if(j <= count_summaries_max) results_temp_count[[length(results_temp_count) + 1]] <- calc_apply
else results_temp_other[[length(results_temp_other) + 1]] <- calc_apply
}
results_temp_count <- dplyr::bind_rows(results_temp_count)
results_temp_other <- dplyr::bind_rows(results_temp_other)
results_temp_count <- format(results_temp_count, scientific = FALSE)
results_temp_other <- format(results_temp_other, scientific = FALSE)
# Convert summaries which have been coerced to numeric but should be dates
if("Date" %in% col_data_type[i]) {
results_temp_other[[col_new]] <- dplyr::if_else(summaries_other[match(results_temp_other$summary, summary_other_names)] %in% date_summaries,
as.character(as.Date(as.numeric(results_temp_other[[col_new]]), origin = "1970/1/1")),
dplyr::if_else(stringr::str_trim(results_temp_other[[col_new]]) == "NA", NA_character_, paste(results_temp_other[[col_new]], "days")))
if(length(results_temp_count) > 0) {
results_temp_count <- dplyr::bind_rows(results_temp_count)
results_temp_count <- format(results_temp_count, scientific = FALSE)
}
if(length(results_temp_other) > 0) {
results_temp_other <- dplyr::bind_rows(results_temp_other)
results_temp_other <- format(results_temp_other, scientific = FALSE)
# Convert summaries which have been coerced to numeric but should be dates
if("Date" %in% col_data_type[i]) {
results_temp_other[[col_new]] <- dplyr::if_else(summaries_other[match(results_temp_other$summary, summary_other_names)] %in% date_summaries,
as.character(as.Date(as.numeric(results_temp_other[[col_new]]), origin = "1970/1/1")),
dplyr::if_else(stringr::str_trim(results_temp_other[[col_new]]) == "NA", NA_character_, paste(results_temp_other[[col_new]], "days")))
}
}
results_temp <- dplyr::bind_rows(results_temp_count, results_temp_other)
if(i == 1) results <- results_temp
Expand Down Expand Up @@ -638,6 +642,8 @@ summary_count_non_missing <- function(x, ...) {
}

summary_sd <- function(x, na.rm = FALSE, na_type = "", ...) {
# needed because e.g. sd(as.character(1:10)) returns a numeric value
if(is.character(x)) return(NA)
if(na.rm && na_type != "" && !na_check(x, na_type = na_type, ...)) return(NA)
else{
return(sd(x,na.rm = na.rm))
Expand Down

0 comments on commit 51f5bf0

Please sign in to comment.