Skip to content

Commit

Permalink
Merge pull request #22 from Boehringer-Ingelheim/20-consider-includin…
Browse files Browse the repository at this point in the history
…g-and-consuming-the-qc-documentation-from-dvtemplates

20 consider including and consuming the qc documentation from dv.templates
  • Loading branch information
zsigmas authored Jun 7, 2024
2 parents 43ed127 + 85d359b commit e9da406
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 32 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,43 @@ jobs:
inst/validation
path: templates

- name: Overwrite quality control scripts with dv.templates ones 🧹
shell: bash
run: |
TEMPLATE_DIR="templates/inst/validation"
REPO_DIR="inst/validation"
if test ! -d "${REPO_DIR}"; then
echo "### Quality Control documentation is not present"
echo "### Include quality control documentation or skip it by creating following file 'inst/validation/skip_qc'"
exit 1
fi
if test -f "${REPO_DIR}/skip_qc"; then
echo "skip_qc file found skipping qc documentation"
exit 0
fi
# Conserve specs.R file
cp "${REPO_DIR}/specs.R" "${TEMPLATE_DIR}/specs.R"
set +e # Disable immediate exit in conflicting parts on error for diff command
DIFF_OUTPUT=$(diff -qr "${TEMPLATE_DIR}" "${REPO_DIR}")
set -e # Enable immediate exit on error after diff command
echo "# Quality control files" | tee -a "${GITHUB_STEP_SUMMARY}"
if [ -n "${DIFF_OUTPUT}" ]; then
echo "Warning: The contents of the directories are different!" | tee -a "${GITHUB_STEP_SUMMARY}"
echo "Modified files:" | tee -a "${GITHUB_STEP_SUMMARY}"
echo "$DIFF_OUTPUT" | tee -a "${GITHUB_STEP_SUMMARY}"
else
echo "The directories are identical." | tee -a "${GITHUB_STEP_SUMMARY}"
fi
rm -rf "${REPO_DIR}"
mv "${TEMPLATE_DIR}" "${REPO_DIR}"
- name: Install package dependencies 📄
uses: boehringer-ingelheim/dv.templates/.github/actions/dependencies@main

Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# dv.templates 0.1.0

- add release checks
- qc check is done with centralized scripts from dv.templates
4 changes: 4 additions & 0 deletions inst/validation/run_validation.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pkg_name <- read.dcf("DESCRIPTION")[, "Package"]
pkg_version <- read.dcf("DESCRIPTION")[, "Version"]
test_results <- tibble::as_tibble(devtools::test())

local({
# This is evaluated inside a local because, otherwise, all the variables created in the chunks of the rendered
# document leak into the environment
Expand Down
28 changes: 9 additions & 19 deletions inst/validation/utils-validation.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
#' Setting up the validation
#'
#' 1. Add package_name
#' 2. Copy that variable and the contents of if block to tests/testthat/setup.R
#' (If you are using the template this may already be in place for you)

package_name <- "dv.templates"

if (FALSE) {
# validation (S)
vdoc <- source(
system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE),
local = TRUE
)[["value"]]
specs <- vdoc[["specs"]]
# validation (F)
}
if (!exists("package_name")) stop("package name must be in the environment when this script is sourced")

#' 2. For those tests that cover an specific spec
#' How to link tests and specs

if (FALSE) {
test_that(
vdoc[["add_spec"]]("my test description", specs[["a_spec"]]),
vdoc[["add_spec"]]("my test description", specs$a_spec),
{
expect_true(TRUE)
}
)
}
#' The specs variable on the call references the one declared in point 1
#' The specs variable on the call references the one declared in specs.R

#' 3. For those tests covering more than one spec.
#' NOTE: It must be c() and not list()
Expand All @@ -47,7 +33,11 @@ if (FALSE) {

if (FALSE) {
my_spec <- specs$my$hier$spec
test_that(vdoc$parse_spec(my_spec, "my test_description"), {
test_that(vdoc[["add_spec"]]("my test_description", my_spec), {
...
})

test_that(vdoc[["add_spec"]]("my test_description", specs[["my"]][["hier"]][["spec"]]), {
...
})
}
Expand Down
13 changes: 9 additions & 4 deletions inst/validation/val_report_child.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@

```{r setup, message = FALSE}
# Import vdoc functions ----
vdoc <- source(
system.file("validation", "utils-validation.R", package = params[["package"]], mustWork = TRUE),
local = TRUE
)[["value"]]
vdoc <- local({
# ##########
# package_name is used # INSIDE # the sourced file below
# ##########
package_name <- params[["package"]]
utils_file_path <- system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE)
source(utils_file_path, local = TRUE)[["value"]]
})
# Set required packages ----
suppressPackageStartupMessages(stopifnot(requireNamespace("DT")))
Expand Down Expand Up @@ -82,6 +86,7 @@ title <- paste(result_symbol, params[["package"]], params[["version"]])
```

## `r title`
Date: `r format(Sys.time(), "%Y-%b-%d %H:%M:%S")`

The following document generates a report for R packages, to satisfy the criteria of a "Released" status under the **Non-GxP** project. The QC report contains the following information:

Expand Down
18 changes: 18 additions & 0 deletions inst/validation_templates/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
template:
bootstrap: 5

navbar:
type: inverted
structure:
left: [intro, reference, articles, tutorials, news, qc]
components:
qc:
text: Quality Control
href: articles/qc.html

articles:

- title: Quality Control
desc: Quality Control
contents:
- qc
11 changes: 11 additions & 0 deletions inst/validation_templates/tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# validation (S)
vdoc <- local({
# ##########
# package_name is used # INSIDE # the sourced file below
# ##########
package_name <- read.dcf("../../DESCRIPTION")[, "Package"]
utils_file_path <- system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE)
source(utils_file_path, local = TRUE)[["value"]]
})
specs <- vdoc[["specs"]]
# validation (F)
32 changes: 32 additions & 0 deletions inst/validation_templates/vignettes/qc.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: "Quality Control"
output:
rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Quality Control}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
echo = FALSE
)
```

```{r, params, echo = FALSE, include = FALSE}
val_param_rds <- "../inst/validation/results/val_param.rds"
val_param_rds_exists <- file.exists(val_param_rds)
if (file.exists(val_param_rds)) params <- readRDS(val_param_rds)
```

```{r, results = "asis", echo = FALSE}
if (val_param_rds_exists) {
res <- knitr::knit_child("../inst/validation/val_report_child.Rmd", quiet = TRUE, envir = environment())
cat(res, sep = "\n")
} else {
"No quality control results found"
}
```
9 changes: 5 additions & 4 deletions scripts/test_qc_pkg.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ if (!dir.exists(validation_root)) {
}

if (file.exists(validation_skip)) {
writeLines("", file.path(validation_results, "skipped_qc"))
success[["valdoc"]] <- NA
} else {

Expand Down Expand Up @@ -127,9 +128,9 @@ summary <- c(
summary,
purrr::imap_chr(success, ~{
symbol <- "\U02753"
symbol <- if (isTRUE(.x)) "\U02705"
symbol <- if (isFALSE(.x)) "\U0274C"
symbol <- if (is.na(.x)) "\U02757"
if (isTRUE(.x)) symbol <- "\U02705"
if (isFALSE(.x)) symbol <- "\U0274C"
if (is.na(.x)) symbol <- "\U02757"
paste(" - ", symbol, .y)
})
)
Expand All @@ -138,7 +139,7 @@ CON <- file(github_summary_file, "a")
on.exit(close(CON))
writeLines(summary, CON)

stopifnot(isTRUE(all(success)))
stopifnot(all(success | is.na(sucess)))

message("##############################")
message("###### BUILD RESULT (F) ######")
Expand Down
13 changes: 8 additions & 5 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package_name <- "dv.templates"
# validation (S)
vdoc <- source(
system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE),
local = TRUE
)[["value"]]
vdoc <- local({
# ##########
# package_name is used # INSIDE # the sourced file below
# ##########
package_name <- read.dcf("../../DESCRIPTION")[, "Package"]
utils_file_path <- system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE)
source(utils_file_path, local = TRUE)[["value"]]
})
specs <- vdoc[["specs"]]
# validation (F)

0 comments on commit e9da406

Please sign in to comment.