From a7d1b13d28caefa884e9bf57a9d384289f7898cf Mon Sep 17 00:00:00 2001 From: Kyle Barrett Date: Mon, 26 Aug 2024 14:19:30 -0400 Subject: [PATCH] Display NA values as blank cells and fix indenting for test files - see inline comments for more details about specific widths that were chosen. --- R/format-report.R | 11 ++++++++++- R/util.R | 5 +++-- man/wrap_text.Rd | 5 +++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/R/format-report.R b/R/format-report.R index 094dffd..953d793 100644 --- a/R/format-report.R +++ b/R/format-report.R @@ -705,6 +705,9 @@ format_traceability_matrix <- function( all_of(c(entry_name, "code_file", "documentation")), function(col){ purrr::map_chr(col, function(cell){ + # Replace NA values with empty strings for display purposes + cell[is.na(cell)] <- "" + # Wrap text if(isTRUE(wrap_cols)){ cell <- wrap_text(cell, width = 24, indent = TRUE, strict = TRUE) } @@ -714,8 +717,14 @@ format_traceability_matrix <- function( ), # Tests can be longer due to page width (pg_width) settings (we make it wider) test_files = purrr::map_chr(.data$test_files, function(tests){ + # Replace NA values with empty strings for display purposes + tests[is.na(tests)] <- "" + # Wrap text if(isTRUE(wrap_cols)){ - tests <- wrap_text(tests, width = 40, strict = TRUE) + # flextable will make its own new line at rendering at 35 characters + # given the current column widths. A width of 34 is therefore the largest + # we can allow if indents are desired (they wont get triggered by flextable's auto newlines) + tests <- wrap_text(tests, width = 34, indent = TRUE, strict = TRUE) } paste(tests, collapse = "\n") }) diff --git a/R/util.R b/R/util.R index fb8fd24..04d1e06 100644 --- a/R/util.R +++ b/R/util.R @@ -129,12 +129,13 @@ deprecate_warning <- function(version, what, details = NULL){ #' @param strict logical (T/F). If `FALSE`, will soft wrap based on the #' characters specified via `wrap_sym`. If `TRUE`, will first soft wrap, and then #' enforce the specified `width`. -#' @param indent logical (T/F). If `TRUE`, indent new lines by two spaces. +#' @param indent logical (T/F). If `TRUE`, indent new lines via a `markdown` tab +#' (`'\t'`) #' #' @details #' `stringr::str_wrap` is not strict with the width for word characters, so #' a helper function was needed. Rather than being 100% strict at following the -#' cutoff width, we attempt to split at whitespace specific symbols commonly +#' cutoff width, we attempt to split at white space and specific symbols commonly #' used in function names and file paths. If this splitting is not sufficient, #' we then perform a strict operation, whereby we cut the line off at exactly #' that width. diff --git a/man/wrap_text.Rd b/man/wrap_text.Rd index 4fc46a3..7caae9a 100644 --- a/man/wrap_text.Rd +++ b/man/wrap_text.Rd @@ -25,7 +25,8 @@ Note that the order you specify these values matters.} characters specified via \code{wrap_sym}. If \code{TRUE}, will first soft wrap, and then enforce the specified \code{width}.} -\item{indent}{logical (T/F). If \code{TRUE}, indent new lines by two spaces.} +\item{indent}{logical (T/F). If \code{TRUE}, indent new lines via a \code{markdown} tab +(\code{'\\t'})} } \description{ Wrap a vector of strings using specific characters @@ -33,7 +34,7 @@ Wrap a vector of strings using specific characters \details{ \code{stringr::str_wrap} is not strict with the width for word characters, so a helper function was needed. Rather than being 100\% strict at following the -cutoff width, we attempt to split at whitespace specific symbols commonly +cutoff width, we attempt to split at white space and specific symbols commonly used in function names and file paths. If this splitting is not sufficient, we then perform a strict operation, whereby we cut the line off at exactly that width.