Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions R/riskmetic.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ is_logical <- function(x) {
}
}

#' Replace 0 or FALSE by no in the summary table
#' @keywords internal
replace_zero_or_false_by_no <- function(value) {
if (value == 0 || isFALSE(value)) {
"No"
} else {
value
}
}


simple_cap <- function(x) {
s <- toupper(substr(x, 1, 1))
paste0(s, substring(x, 2))
Expand All @@ -96,8 +107,15 @@ summary_table <- function(risk) {
for (column in setdiff(colnames(risk), excluded_columns)) {
risk[,column] <- is_logical(risk[, column])
}
risk$has_examples <- sprintf("%.2f%%", risk$has_examples*100)
risk$bugs_status <- sprintf("%.2f%% closed", risk$bugs_status*100)

columns_to_add_no <- c("has_news", "has_vignettes", "has_website", "has_bug_reports_url", "news_current") |>
intersect(colnames(risk))
for (column in columns_to_add_no) risk[,column] <- replace_zero_or_false_by_no(risk[, column])


if(is.numeric(risk$has_examples)) risk$has_examples <- sprintf("%.2f%%", risk$has_examples*100)
if(is.numeric(risk$bugs_status)) risk$bugs_status <- sprintf("%.2f%% closed", risk$bugs_status*100)

# We change to numeric because it is a list with different elements we only use the numeric value
if(!is.null(risk$size_codebase)) risk$size_codebase <- as.numeric(risk$size_codebase)
if (risk$has_vignettes > 0) {
Expand Down
2 changes: 1 addition & 1 deletion inst/report/package/pkg_template.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ if (isTRUE(is_html)) {
pagination = FALSE,
details = function(index) {
if(index %in% indexes_collapsed_rows) {
collapsed_content <- switch(x$Section[index],
collapsed_content <- switch(summary_data$Section[index],
"Exported namespace" = namespace_table,
"Dependencies" = dependencies_table,
"Reverse dependencies" = reverse_dependencies,
Expand Down
274 changes: 0 additions & 274 deletions inst/report/pkg_template.qmd

This file was deleted.

25 changes: 25 additions & 0 deletions tests/testthat/test-report.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
describe("Run test for the report", {
tmp_folder <- withr::local_tempdir(
pattern = "report",
tmpdir = tempdir(),
fileext = "",
.local_envir = parent.frame(),
clean = TRUE
)
withr::local_options("riskreports_output_dir" = tmp_folder)

it("should be generated in all formats", {
expect_no_error({
pr <- package_report(
package_name = "dplyr",
package_version = "1.1.4",
params = list(
assessment_path = system.file("assessments/dplyr.rds", package = "riskreports"),
source = "pkg_install"),
quiet = TRUE,
output_format = "all"
)
})
})

})
9 changes: 9 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ test_that("is_empty returns TRUE if the argument is withint the expected empty c
expect_true(is_empty(""))
expect_false(is_empty(letters[1]))
})

test_that("replace_zero_or_false_by_no returns 'No' if value is zero ir FALSE", {
value_1 <- FALSE
value_2 <- 0

expect_identical("No", replace_zero_or_false_by_no(value_1))
expect_identical("No", replace_zero_or_false_by_no(value_2))
expect_identical(TRUE, replace_zero_or_false_by_no(TRUE))
})