Skip to content

Conversation

@Zhenglei-BCS
Copy link
Collaborator

  • added a custom_report folder, will be merged into report folder
  • added a custo _report function, will be mergerd into the main function.

llrs-roche and others added 12 commits February 20, 2025 15:45
Co-authored-by: Alvaro Sanchez <71273913+svalvaro@users.noreply.github.com>
Co-authored-by: svalvaro <sanchezvillalba.alvaro@gmail.com>
Co-authored-by: osenan <oriol@praenoscere.com>
Co-authored-by: osenan <oriol@praenoscere.com>
Co-authored-by: Rabii Bouhestine <rabiibouhestine@outlook.com>
@Zhenglei-BCS Zhenglei-BCS mentioned this pull request Jul 10, 2025
2 tasks
@Zhenglei-BCS
Copy link
Collaborator Author

Zhenglei-BCS commented Jul 10, 2025

Summary of Changes from Original package_report() Function

Here’s a brief overview of the key modifications made to the original package_report() function to support customized R package risk assessment reporting:

  • New Parameters for Branding: Added logo_path, logo_path_dark, and r_validation_logo_path to support custom logos for light/dark modes (header) and R Validation Hub branding (footer), with defaults set to "r_validation_logo.png".
  • Dual-Logo Setup: Modified top_page.html to include both light and dark mode logos in a container <div>, with CSS to toggle visibility based on theme.
  • R Validation Hub Footer: Created footer.html in the template directory to add the R Validation Hub logo and text ("Generated by R-Validation Hub workflow") at the bottom of HTML reports.
  • File Accessibility: Added logic to copy all logo files to the rendering directory with unique filenames (e.g., logo_light.png) to ensure accessibility during rendering, addressing potential path resolution issues.

In addition to changes in the package_report() function, the Quarto template has been updated to include the new parameters in the YAML front matter, ensuring they are accessible during rendering.

PDF issues

Unlike HTML, PDF output via Typst does not support dynamic CSS-based theme switching for light/dark logos. Maybe We should also explore Typst-specific customization in the Quarto YAML (header-includes or footer-includes?) to automate footer inclusion for PDF output.

  • Currently tried using ::: {.content-visible when-format="pdf"} syntax for including logos in PDF/Typst output, added the following to the template but did not work
::: {.content-visible when-format="pdf"}
#figure(image("logo_light.png", width: 30%), caption: "Logo")
:::



::: {.content-visible when-format="pdf"}
#figure(image("r_validation_logo.png", width: 30%), caption: "Generated by R-Validation Hub workflow")
:::

@Zhenglei-BCS Zhenglei-BCS marked this pull request as ready for review July 10, 2025 19:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new custom report feature—allowing light/dark logos and future color theming—by adding a custom_report folder, updating templates, and extending package_report() with new parameters.

  • Added logo_path, logo_path_dark, r_validation_logo_path, primary_color, and secondary_color to the report API
  • Updated Quarto templates and HTML/CSS to render dual‐mode logos and a footer
  • Expanded documentation (.Rd and vignettes) and included example R functions

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vignettes/articles/Generate-Customized-Report.Rmd Spelling fix and updated usage example for custom logos
man/package_report.Rd Documented new logo and color arguments
man/custom_package_report.Rd Added custom report Rd and arguments; example usage mismatch
inst/report/package/top_page.html Replaced single logo with dual‐logo container and dynamic title
inst/report/package/pkg_template.qmd Injected new params and PDF fallback logo
inst/report/package/footer.html Introduced a footer with R Validation Hub logo
R/utils.R Duplicate is.empty definition
R/reporter.R Copying logos and CSS removal logic
Comments suppressed due to low confidence (3)

inst/dev/custom_report.R:10

  • The @param block documents primary_color and secondary_color but is missing @param logo_path_dark; please add documentation for the logo_path_dark argument to keep the Rd in sync with the function signature.
#' @param primary_color Hex color code for primary styling (e.g., links, headers). Defaults to "#007BFF" (blue). Currently not applied; reserved for future customization.

man/custom_package_report.Rd:59

  • The example calls package_report() instead of custom_package_report(); update this to reflect the correct function name for the custom report.
pr <- package_report(

R/reporter.R:135

  • The new logo‐copying and CSS removal logic isn’t covered by tests; consider adding unit or integration tests for logo_path/logo_path_dark handling to prevent regressions.
  logo_to_remove <- c()

Comment on lines +41 to +46
is.empty <- function(x) {
is.null(x) || is.na(x) || !nzchar(x)
}
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’ve introduced is.empty which duplicates is_empty; consider consolidating to a single helper to avoid confusion and reduce code duplication.

Suggested change
is.empty <- function(x) {
is.null(x) || is.na(x) || !nzchar(x)
}
# Removed the duplicate is.empty function. Use is_empty instead.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

@Zhenglei-BCS Zhenglei-BCS Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is used somewhere else, @llrs-roche , I copied the original reporter.R and there is an is.empty function, and I put it to the utils.R, Copilot says it is redundant, can you confirm? I also kept the original function in orig_reporter.R, if you agree, we can also delete that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a real issue, I duplicated the functions. Maybe initially they did different things but now they have the same body. This should be fixed in all files of the package (not just on the ones you modified). So maybe we can left it as is and we address it later, or we can address it here for custom_report.R, orig_reporter.R, ...
We should replace is_empty by is.empty (in tests too) this would be the minimal diff.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Collaborator

@llrs-roche llrs-roche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of having a specific vignette for customizing the report.
However, how the packages provides this customization is not clear yet to me.
Adding a new function for each customization doesn't look sustainable in light of the _brand.yaml file (but that hasn't been tested). See the specific comments. In addition, this PR adds some folders inst/dev that I am not sure what they are.

This PR can be the base to write more robust code for customization.

Comment on lines +41 to +46
is.empty <- function(x) {
is.null(x) || is.na(x) || !nzchar(x)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a real issue, I duplicated the functions. Maybe initially they did different things but now they have the same body. This should be fixed in all files of the package (not just on the ones you modified). So maybe we can left it as is and we address it later, or we can address it here for custom_report.R, orig_reporter.R, ...
We should replace is_empty by is.empty (in tests too) this would be the minimal diff.

Comment on lines +68 to +76
params$package_name <- package_name
params$package_version <- package_version
params$image <- get_image_name(params)
params$logo_path <- logo_path
params$logo_path_dark <- logo_path_dark
params$primary_color <- primary_color
params$secondary_color <- secondary_color
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the arguments are then added to params. Good catch! I think it would make more sense to directly pass them as params, as I don't see any transformation or interaction before adding them to the parameters.

Comment on lines 142 to 228
# Placeholder for custom CSS or SCSS styling
# Note: Add custom styling here in the future. Options include:
# - Inline CSS by appending a <style> block to top_page_file with custom styles using params$primary_color and params$secondary_color.
# - Creating a separate custom CSS file in render_dir and ensuring it's referenced in the Quarto template YAML under format:html:include-in-header.
# - Dynamically updating SCSS files like custom.scss or custom_light.scss with color variables before rendering, if supported by the build process.
# Minimal CSS for dual-logo visibility in light and dark modes:
custom_style <- c(
"<style>",
" /* Dual-logo styling for light and dark modes */",
" .logo-container { position: relative; display: inline-block; }",
" .logo-light { display: block; }",
" .logo-dark { display: none; }",
" @media (prefers-color-scheme: dark) {",
" .logo-light { display: none; }",
" .logo-dark { display: block; }",
" }",
"</style>"
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This custom_style variable is not sustainable for all styles different organizations will like. The _brand.yaml file supported by quarto, allows to customize light and dark logos too:

logo:
  small: logos/icon.png
  medium:
    light: logos/header-logo-light.png
    dark: logos/header-logo-dark.png
  large: logos/full-logo.svg

Copy link
Collaborator Author

@Zhenglei-BCS Zhenglei-BCS Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Difficulties in using this approach:

  • Quarto up to 1.6 did not clearly support dark mode branding (such as different logos or themes for dark mode) through the _brand.yml configuration. There are many ways to tweak it to work. Also it serves more for website project or project based, rather than single html file rendering. (Seems that the top.html need to be reconstructed in this case.)
  • 1.7 supports dark and light both, but I don't have enough time to test it out yet as my RStudio does not pick up the newly installed quarto automatically but keeps using the quarto.exe under RStudio. I will have to try under Ubuntu environment instead. I will leave it here and get back to this after my vacation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, with the reports we are on the edge of what quarto can provide. But I don't think we have other options that would have this. Rmarkdown can't provide this integration with multiple themes and the customizations we want as easily.

I too think that working with a single file is easier with Rmarkdown than with quarto. But ideally that drawback is reduced as the reports are generated for multiple packages.

About the problems with the quarto version picked on your computer I found a discussion. Which suggest this approach:

The version used in RStudio can also be forced by setting RSTUDIO_QUARTO env var

I hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants