-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4274916
commit a788434
Showing
5 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' Render a QC Report Document | ||
#' | ||
#' This function generates a QC report based on the files within the QC log | ||
#' and renders it into a PDF report. | ||
#' | ||
#' The QC status of all files in the QC log will be displayed. | ||
#' | ||
#' @param .output_dir Character string (optional). Path to the directory where the output PDF | ||
#' should be saved. If not provided, the document will not be saved locally. | ||
#' | ||
#' @return Invisible. The function will save a PDF report named "qc-report-(current date).pdf" | ||
#' to the specified output directory (if available). If the R session is interactive, it will also | ||
#' open the PDF in the default browser. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' renderQCReport() | ||
#' } | ||
#' | ||
#' @export | ||
renderQCReport <- function(.output_dir = NULL) { | ||
|
||
reportRes <- list() | ||
|
||
reportRes$project <- basename(logRoot()) | ||
|
||
reportRes$logSum <- logSummary() | ||
|
||
if (is.null(.output_dir)) { | ||
.output_dir <- tempdir() | ||
} else { | ||
if (!dir.exists(.output_dir)) { | ||
stop(.output_dir, " does not exist") | ||
} | ||
} | ||
|
||
output_file <- paste0("qc-report-", Sys.Date(), ".pdf") | ||
output_path <- file.path(.output_dir, output_file) | ||
|
||
rmarkdown::render( | ||
input = system.file("templates", "QCReport.Rmd", package = "review"), | ||
output_file = output_path, | ||
params = list(reportRes = reportRes), | ||
envir = new.env(), | ||
quiet = TRUE | ||
) | ||
|
||
if (interactive()) { | ||
utils::browseURL(output_path) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
params: | ||
reportRes: "`r list()`" | ||
title: "QC Report" | ||
subtitle: "`r params$reportRes$project`" | ||
date: "`r format(Sys.time(), '%d %B, %Y %H:%M %Z')`" | ||
output: pdf_document | ||
header-includes: | ||
- \usepackage{caption} | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = FALSE) | ||
``` | ||
|
||
```{r message=FALSE, warning=FALSE} | ||
log_summary_data <- params$reportRes$logSum | ||
log_summary_data %>% | ||
dplyr::select(file, revf, headf, time) %>% | ||
dplyr::mutate( | ||
Status = dplyr::case_when( | ||
revf == headf ~ "QCed", | ||
TRUE ~ "Needs QC" | ||
), | ||
`QC date` = dplyr::if_else(revf == headf, time, NA_character_), | ||
`QC date` = as.Date(`QC date`) | ||
) %>% | ||
dplyr::select(-time) %>% | ||
dplyr::rename( | ||
File = file, | ||
`QCed...revision` = revf, | ||
`Last modified...revision` = headf, | ||
) %>% | ||
pmtables::st_new() %>% | ||
pmtables::st_left(File = pmtables::col_ragged(5)) %>% | ||
pmtables::stable_long() %>% | ||
pmtables::st_asis() | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
if (Sys.getenv("METWORX_VERSION") != "") { | ||
|
||
create_test_svn() | ||
|
||
logAssign("script/model-management.R") | ||
logAccept("script/box-sample-code.R") | ||
|
||
test_that("renderQCReport works with valid directory", { | ||
|
||
renderQCReport(.output_dir = logRoot()) | ||
|
||
# Check that the output file was created | ||
expect_true(file.exists(file.path(logRoot(), paste0("qc-report-", Sys.Date(), ".pdf")))) | ||
|
||
}) | ||
} |