diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 097947e..58e0614 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -32,6 +32,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tinytex: true + version: 1.7.13 - uses: r-lib/actions/check-r-package@v2 with: diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..bfc9f4d --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,49 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + release: + types: [published] + workflow_dispatch: + +name: pkgdown.yaml + +permissions: read-all + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.5.0 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/DESCRIPTION b/DESCRIPTION index b8d9efd..0d85b91 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,7 @@ License: MIT + file LICENSE URL: https://github.com/pharmaR/riskreports BugReports: https://github.com/pharmaR/riskreports/issues Depends: - R (>= 3.5.0) + R (>= 4.4.0) Imports: methods, quarto (>= 1.4.4) diff --git a/R/reporter.R b/R/reporter.R index 5be7e6d..633fa27 100644 --- a/R/reporter.R +++ b/R/reporter.R @@ -7,16 +7,18 @@ #' @param params A list of execute parameters passed to the template #' @param ... Additional arguments passed to `quarto::quarto_render()` #' -#' @return A report +#' @return A path to the reports generated, called by its side effects. +#' @export #' @examples -#' package_report( +#' pr <- package_report( #' package_name = "dplyr", #' package_version = "1.1.4", #' params = list( +#' assessment_path = system.file("assessments/dplyr.rds", package = "riskreports"), #' image = "rhub/ref-image") #' ) -#' -#' @export +#' pr +#' file.remove(pr) package_report <- function( package_name, package_version, @@ -41,7 +43,7 @@ package_report <- function( } full_name <- paste0(package_name, "_v", package_version) - output_file <- paste0("validation_report_", full_name,".html") + output_file <- paste0("validation_report_", full_name, ".qmd") params$package_name <- package_name params$package_version <- package_version @@ -57,26 +59,51 @@ package_report <- function( params$assessment_path <- normalizePath(params$assessment_path, mustWork = TRUE) } # Bug on https://github.com/quarto-dev/quarto-cli/issues/5765 + + v <- quarto::quarto_version() + if (v < package_version("1.7.13")) { + warning("Please install the latest (devel) version of Quarto") + } + # https://github.com/quarto-dev/quarto-r/issues/81#issuecomment-1375691267 + # quarto rendering happens in the same place as the file/project + # To avoid issues copy to a different place and render there. + render_dir <- output_dir() + fc <- file.copy(from = template_path, + to = file.path(render_dir, output_file), overwrite = TRUE, + copy.date = TRUE) + + if (any(!fc)) { + stop("Copying to the rendering directory failed.") + } + + template <- list.files(render_dir, full.names = TRUE) + template <- template[endsWith(template, "qmd")] + + if (length(template) > 1) { + stop("There are more than one template!\n", + "Please have only one quarto file on the directory.") + } + + prefix_output <- paste0("validation_report_", full_name) + pre_rendering <- list.files(render_dir, full.names = TRUE) + suppressMessages({suppressWarnings({ out <- quarto::quarto_render( - template_path, + input = template, output_format = "all", execute_params = params, ... ) })}) - # Move reports after creation (work around issue https://github.com/quarto-dev/quarto-cli/issues/5765) - lf <- list.files(dirname(template_path), full.names = TRUE) - files_template <- lf[!dir.exists(lf)] - file_name <- tools::file_path_sans_ext(basename(template_path)) - files_template <- files_template[startsWith(basename(files_template), - file_name)] - files_template <- files_template[!endsWith(files_template, ".qmd")] - output_file = paste0("validation_report_", full_name, - ".", tools::file_ext(files_template)) - file.rename(files_template, output_file) - invisible(output_file) + fr <- file.remove(file.path(render_dir, output_file)) + if (any(!fr)) { + warning("Failed to remove the quarto template used from the directory.") + } + + post_rendering <- list.files(render_dir, full.names = TRUE) + output_files <- setdiff(post_rendering, pre_rendering) + invisible(output_files) } is.empty <- function(x) { diff --git a/R/utils.R b/R/utils.R index 8e89dd4..1d765b7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -17,3 +17,18 @@ fill_in <- function(list, names) { list[missing_names] <- NA list } + + +output_dir <- function() { + opt <- getOption("riskreports_output_dir", default = NULL) + env <- Sys.getenv("RISKREPORTS_OUTPUT_DIR", unset = getwd()) + + opt %||% env +} + +rendering_dir <- function() { + opt <- getOption("riskreports_rendering_dir", default = NULL) + env <- Sys.getenv("RISKREPORTS_RENDERING_DIR", unset = tempdir()) + + opt %||% env +} diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..d71acfb --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,4 @@ +url: ~ +template: + bootstrap: 5 + diff --git a/inst/assessments/dplyr.rds b/inst/assessments/dplyr.rds new file mode 100644 index 0000000..275c8f3 Binary files /dev/null and b/inst/assessments/dplyr.rds differ diff --git a/inst/report/pkg_template.qmd b/inst/report/pkg_template.qmd index d7d0cc1..aef3f7f 100644 --- a/inst/report/pkg_template.qmd +++ b/inst/report/pkg_template.qmd @@ -1,6 +1,5 @@ --- title: "Validation Report - `r paste0(params$package_name, '@', params$package_version)`" -date: "`r Sys.time()`" date-format: "ddd MMM DD hh:mm:ss A YYYY" params: package_name: dplyr @@ -83,7 +82,7 @@ d_riskmetric <- readRDS(risk_path) # Assesment produces a data.frame with one row r_riskmetric <- riskreports::assessment(d_riskmetric) -is_na <- sapply(r_riskmetric, is.na) +is_na <- sapply(r_riskmetric, function(x){is.na(x) || (is.character(x) && startsWith(x, "no applicable"))}) knitr::kable(r_riskmetric[, !is_na]) # Use this to have some summary text and report it. # d_riskmetric ``` @@ -120,15 +119,15 @@ d_riskmetric$export_help[sort(d_riskmetric$exported_namespace)] ### Examples -There are `r sum(d_riskmetric$has_examples)` help pages with examples, from `r length(d_riskmetric$has_examples)` (`r sprintf("%0.2f", sum(d_riskmetric$has_examples)/length(d_riskmetric$has_examples)*100) ` %). +There are `r if (!is_na["has_examples"]) sum(d_riskmetric$has_examples)` help pages with examples, from `r if (!is_na["has_examples"]) {length(d_riskmetric$has_examples)}` (`r if (!is_na["has_examples"]) {sprintf("%0.2f", sum(d_riskmetric$has_examples)/length(d_riskmetric$has_examples)*100)} else {"?"} ` %). ### NEWS -The package has `r d_riskmetric$has_news` NEWS file and it is `r if(!d_riskmetric$news_current) "not"` current. +The package has `r if ("has_news" %in% names(d_riskmetric) && !is.null(d_riskmetric$has_news)) print(d_riskmetric$has_news)` NEWS file and it is `r if (is.null(d_riskmetric$news_current) && !d_riskmetric$news_current) "not"` current. ### License -The package uses `r d_riskmetric$license`. +The package uses `r if ("license" %in% names(d_riskmetric) && !is.null(d_riskmetric$license)) print(d_riskmetric$license)`. diff --git a/man/package_report.Rd b/man/package_report.Rd index 056b722..faff9c8 100644 --- a/man/package_report.Rd +++ b/man/package_report.Rd @@ -27,17 +27,19 @@ package_report( \item{...}{Additional arguments passed to \code{quarto::quarto_render()}} } \value{ -A report +A path to the reports generated, called by its side effects. } \description{ Reports about a package } \examples{ -package_report( +pr <- package_report( package_name = "dplyr", package_version = "1.1.4", params = list( + assessment_path = system.file("assessments/dplyr.rds", package = "riskreports"), image = "rhub/ref-image") ) - +pr +file.remove(pr) }