ewenharrison / finalfit

Compare f0af10d ... +4 ... 7705a63


@@ -105,7 +105,7 @@
Loading
105 105
															 column = TRUE, total_col = FALSE, orderbytotal = FALSE,
106 106
															 digits = c(1, 1, 3, 1), 
107 107
															 na_include = FALSE, na_include_dependent = FALSE, 
108 -
															 na_complete_cases = FALSE, na_to_p = FALSE,
108 +
															 na_complete_cases = FALSE, na_to_p = FALSE, na_to_prop = TRUE,
109 109
															 fit_id = FALSE,
110 110
															 add_dependent_label = FALSE,  
111 111
															 dependent_label_prefix = "Dependent: ", dependent_label_suffix = "",
@@ -427,17 +427,35 @@
Loading
427 427
												 		dplyr::count(!! sym(..1), .drop = FALSE) %>% 
428 428
												 		dplyr::ungroup() %>% 
429 429
												 		tidyr::drop_na() %>% 
430 -
												 		dplyr::mutate(grand_total = sum(n)) %>% 
430 +
												 		{ if(na_to_prop) {
431 +
												 			dplyr::mutate(., grand_total = sum(n))
432 +
												 		} else {
433 +
												 			dplyr::mutate(., grand_total = sum(n[.[[2]] != "(Missing)"], na.rm = TRUE))
434 +
												 		}
435 +
												 		} %>% 
431 436
												 		dplyr::group_by_at(2) %>% 
432 437
												 		dplyr::mutate(row_total = sum(n),
433 438
												 									col_total_prop = 100 * row_total / grand_total) %>% 
434 439
												 		{ if(column) {
435 440
												 			dplyr::group_by(., !! sym(dependent)) %>% 
436 -
												 				dplyr::mutate(
437 -
												 					col_total = sum(n),
438 -
												 					prop = 100 * n / col_total,
439 -
												 					Total = format_n_percent(row_total, col_total_prop, digits[[4]])
440 -
												 				) %>% 
441 +
												 				# Choose to include missing in column proportions 
442 +
												 				{ if(na_to_prop) {
443 +
												 					dplyr::mutate(., 
444 +
												 												col_total = sum(n),
445 +
												 												prop = 100 * n / col_total,
446 +
												 												Total = format_n_percent(row_total, col_total_prop, digits[[4]])
447 +
												 					)
448 +
												 				} else {
449 +
												 					dplyr::mutate(., 
450 +
												 												col_total = sum(n[.[[2]] != "(Missing)"], na.rm = TRUE),
451 +
												 												prop = 100 * n / col_total,
452 +
												 												prop = if_else(!! sym(names(.)[2]) == "(Missing)", NA_real_, prop),
453 +
												 												col_total_prop = if_else(!! sym(names(.)[2]) == "(Missing)", 
454 +
												 																								 NA_real_, col_total_prop),
455 +
												 												Total = format_n_percent(row_total, col_total_prop, digits[[4]], 
456 +
												 																								 na_include = FALSE)
457 +
												 				)}
458 +
												 				} %>% 
441 459
												 				dplyr::select(-col_total)
442 460
												 		} else { 
443 461
												 			dplyr::group_by_at(., 2) %>% 
@@ -449,7 +467,7 @@
Loading
449 467
												 		} %>% 
450 468
												 		dplyr::ungroup() %>% 
451 469
												 		dplyr::mutate(
452 -
												 			value = format_n_percent(n, prop, digits[4])
470 +
												 			value = format_n_percent(n, prop, digits[4], na_include = FALSE)
453 471
												 		) %>%
454 472
												 		dplyr::select(-prop, -n, -grand_total, -col_total_prop) %>% 
455 473
												 		tidyr::pivot_wider(names_from = !! dependent, values_from = value) %>% 

@@ -424,12 +424,17 @@
Loading
424 424
#' @param n Value
425 425
#' @param percent Value
426 426
#' @param digits Value
427 +
#' @param na_include When proportion missing, include in parentheses?
427 428
#'
428 429
#' @export
429 430
#'
430 -
format_n_percent = function(n, percent, digits) {
431 +
format_n_percent = function(n, percent, digits, na_include = TRUE) {
431 432
	percent = round_tidy(percent, digits)
432 -
	paste0(n, " (", percent, ")")
433 +
	out = paste0(n, " (", percent, ")")
434 +
	if(!na_include){
435 +
		out = gsub(" \\(NA\\)", "", out)
436 +
	}
437 +
	return(out)
433 438
}
434 439
435 440
#' Remove intercept from model output

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
R -0.30% 82.15%
Project Totals (39 files) 82.15%
Loading