Skip to content

Commit 6dc2e7a

Browse files
osenanosenanrabiibouhestine
authored
Fix html format and content (#35)
Co-authored-by: osenan <oriol@praenoscere.com> Co-authored-by: Rabii Bouhestine <rabiibouhestine@outlook.com>
1 parent b426f65 commit 6dc2e7a

File tree

5 files changed

+66
-277
lines changed

5 files changed

+66
-277
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) {

inst/report/package/pkg_template.qmd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ The following metrics are derived from the `riskmetric` R package.
7575

7676
```{r read-riskmetric, warning=FALSE}
7777
d_riskmetric <- readRDS(risk_path)
78+
79+
# Required fields
80+
required_fields <- c("r_cmd_check", "license", "remote_checks", "covr_coverage")
81+
82+
# Missing fields
83+
missing_fields <- setdiff(required_fields, names(d_riskmetric))
84+
85+
# Assign default error structure for missing fields to avoid errors
86+
for (field in missing_fields) {
87+
d_riskmetric[[field]] <- structure(NA, class = "risk_metric_error")
88+
}
7889
```
7990

8091
```{r create_r_riskmetric, warning=FALSE}
@@ -190,7 +201,7 @@ if (isTRUE(is_html)) {
190201
pagination = FALSE,
191202
details = function(index) {
192203
if(index %in% indexes_collapsed_rows) {
193-
collapsed_content <- switch(x$Section[index],
204+
collapsed_content <- switch(summary_data$Section[index],
194205
"Exported namespace" = namespace_table,
195206
"Dependencies" = dependencies_table,
196207
"Reverse dependencies" = reverse_dependencies,

inst/report/pkg_template.qmd

Lines changed: 0 additions & 274 deletions
This file was deleted.

tests/testthat/test-report.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
describe("Run test for the report", {
2+
tmp_folder <- withr::local_tempdir(
3+
pattern = "report",
4+
tmpdir = tempdir(),
5+
fileext = "",
6+
.local_envir = parent.frame(),
7+
clean = TRUE
8+
)
9+
withr::local_options("riskreports_output_dir" = tmp_folder)
10+
11+
it("should be generated in all formats", {
12+
expect_no_error({
13+
pr <- package_report(
14+
package_name = "dplyr",
15+
package_version = "1.1.4",
16+
params = list(
17+
assessment_path = system.file("assessments/dplyr.rds", package = "riskreports"),
18+
source = "pkg_install"),
19+
quiet = TRUE,
20+
output_format = "all"
21+
)
22+
})
23+
})
24+
25+
})

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)