Skip to content

Commit

Permalink
Display NA values as blank cells and fix indenting for test files
Browse files Browse the repository at this point in the history
 - see inline comments for more details about specific widths that were chosen.
  • Loading branch information
barrettk committed Aug 26, 2024
1 parent 6d91533 commit a7d1b13
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
11 changes: 10 additions & 1 deletion R/format-report.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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")
})
Expand Down
5 changes: 3 additions & 2 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions man/wrap_text.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7d1b13

Please sign in to comment.