Skip to content

Commit 5f5d610

Browse files
author
osenan
committed
refactor: replace results to no to display in summary table
1 parent 58e539f commit 5f5d610

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

R/riskmetic.R

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ is_logical <- function(x) {
7878
}
7979
}
8080

81+
#' Replace 0 or FALSE by no in the summary table
82+
#' @keywords internal
83+
replace_zero_or_false_by_no <- function(value) {
84+
if (value == 0 || isFALSE(value)) {
85+
"No"
86+
} else {
87+
value
88+
}
89+
}
90+
91+
8192
simple_cap <- function(x) {
8293
s <- toupper(substr(x, 1, 1))
8394
paste0(s, substring(x, 2))
@@ -96,8 +107,15 @@ summary_table <- function(risk) {
96107
for (column in setdiff(colnames(risk), excluded_columns)) {
97108
risk[,column] <- is_logical(risk[, column])
98109
}
99-
risk$has_examples <- sprintf("%.2f%%", risk$has_examples*100)
100-
risk$bugs_status <- sprintf("%.2f%% closed", risk$bugs_status*100)
110+
111+
columns_to_add_no <- c("has_news", "has_vignettes", "has_website", "has_bug_reports_url", "news_current") |>
112+
intersect(colnames(risk))
113+
for (column in columns_to_add_no) risk[,column] <- replace_zero_or_false_by_no(risk[, column])
114+
115+
116+
if(is.numeric(risk$has_examples)) risk$has_examples <- sprintf("%.2f%%", risk$has_examples*100)
117+
if(is.numeric(risk$bugs_status)) risk$bugs_status <- sprintf("%.2f%% closed", risk$bugs_status*100)
118+
101119
# We change to numeric because it is a list with different elements we only use the numeric value
102120
if(!is.null(risk$size_codebase)) risk$size_codebase <- as.numeric(risk$size_codebase)
103121
if (risk$has_vignettes > 0) {

tests/testthat/test-utils.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ test_that("is_empty returns TRUE if the argument is withint the expected empty c
1717
expect_true(is_empty(""))
1818
expect_false(is_empty(letters[1]))
1919
})
20+
21+
test_that("replace_zero_or_false_by_no returns 'No' if value is zero ir FALSE", {
22+
value_1 <- FALSE
23+
value_2 <- 0
24+
25+
expect_identical("No", replace_zero_or_false_by_no(value_1))
26+
expect_identical("No", replace_zero_or_false_by_no(value_2))
27+
expect_identical(TRUE, replace_zero_or_false_by_no(TRUE))
28+
})

0 commit comments

Comments
 (0)