-
Notifications
You must be signed in to change notification settings - Fork 1
Various enhancements to support reporting #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #33 +/- ##
==========================================
+ Coverage 20.58% 25.44% +4.86%
==========================================
Files 33 34 +1
Lines 1404 1462 +58
==========================================
+ Hits 289 372 +83
+ Misses 1115 1090 -25 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| method(convert, list(class_character, class_pkg)) <- | ||
| function(from, to, ...) { | ||
| if (endsWith(tolower(from), ".rds")) { | ||
| convert(readRDS(from), class_pkg) | ||
| } else if (grepl("\\bPackage:", from[[1L]])) { | ||
| pkg_from_dcf(from, ...) | ||
| } else { | ||
| pkg(from, ...) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few extra handlers for converting a character string into a pkg object. Specifically ensuring that we can handle Rds file paths and DCF strings.
With these, whatever is passed to the report's package parameter, we can just run convert() on it to build a pkg() object and handle Rds paths, DCF strings and package names through a single interface.
| method(convert, list(class_list, class_pkg)) <- | ||
| function(from, to, ...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly added handling for lists, which were effectively already handled inside the from_dcf method. Now it's just split into building a list from the DCF contents and then converting the list into a pkg object.
| nodes |> | ||
| xml2::xml_attr("href") |> | ||
| basename() |> | ||
| tools::file_path_sans_ext() |> | ||
| unique() |> | ||
| length() | ||
| paths <- xml2::xml_attr(nodes, "href") | ||
| filenames <- basename(paths) | ||
| filestems <- tools::file_path_sans_ext(filenames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of an unrelated fix, but noticed that the use of |> would force us to bump our minimum R version support so I just converted them into more traditional calls.
| capture <- evaluate::evaluate( | ||
| evaluate_fn, | ||
| stop_on_error = 1L, | ||
| debug = !isTRUE(quiet), | ||
| output_handler = evaluate::new_output_handler(value = identity) | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When logging is enabled we use evaluate to capture it.
It's off by default, since it's been a bit problematic in riskmetric; though here we're offloading all the nastiness of sinking output to a more mature package. Hopefully this is a bit more stable than what we had before, but still would prefer to keep it off by default until we have had an opportunity to stress test it a bit more.
| format.evaluate_evaluation <- function( | ||
| x, | ||
| ..., | ||
| style = c("text", "ansi", "html") | ||
| ) { | ||
| style <- match.arg(style) | ||
|
|
||
| if ( | ||
| identical(style, "html") && !requireNamespace("htmltools", quietly = TRUE) | ||
| ) { | ||
| stop( | ||
| "html formatting of evaluation logs requires suggested package ", | ||
| "`htmltools`" | ||
| ) | ||
| } | ||
|
|
||
| out <- utils::capture.output(evaluate::replay(x)) | ||
| switch( | ||
| style, | ||
| text = paste(cli::ansi_strip(out), collapse = "\n"), | ||
| ansi = paste(out, collapse = "\n"), | ||
| html = { | ||
| html <- cli::ansi_html(paste(out, collapse = "\n")) | ||
| htmltools::tags$div( | ||
| style = cli::ansi_html_style(colors = 8L), | ||
| htmltools::tags$pre(htmltools::HTML(html)) | ||
| ) | ||
| } | ||
| ) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To support prettier output of logs in the report, allow a style option that will hopefully make it easier to emit plain text or rich html reports.
jthompson-arcus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dgkf focused on the logging as requested. I don't think any of this structure would pose an issue to the accompanying Shiny app.
I did have a couple comments below.
I spent some time before the holidays familiarizing myself with
val.reportand made a few changes toval.meterthat I think will help streamline the reporting process.I had a few goals in mind:
packageparameter to be more agnostic. Ideally, we should be able to pass in a pre-calculatedpkgobject (by Rds path), a DCF-formatted string of metrics (for example, from our repository), or a package name to be calculated on the fly.Will annotate the changes inline in comments.
@jthompson-arcus - let me know what you think of the logs capture. I know this was a contentious feature in
riskmetricand would be curious to hear your thoughts on this approach.@llrs-roche - would love to get your thoughts on some of the reporting-oriented changes.