Skip to content

Creating default print methods for class sr_model#114

Open
sschildhauer wants to merge 84 commits intomainfrom
default_print
Open

Creating default print methods for class sr_model#114
sschildhauer wants to merge 84 commits intomainfrom
default_print

Conversation

@sschildhauer
Copy link
Copy Markdown
Collaborator

I am creating a default print methods for sr_model using the S3 object system. The default print provides the mean value of the posterior distribution for each parameter and all stratification iso_type combinations.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 9, 2025

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
R/print.sr_model.R 94.73% 1 Missing ⚠️
Files with missing lines Coverage Δ
R/Run_Mod.R 100.00% <ø> (ø)
R/expect_snapshot_data.R 100.00% <ø> (ø)
R/print.sr_model.R 94.73% <94.73%> (ø)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jul 9, 2025

📖 https://ucd-serg.github.io/serodynamics/preview/pr114
Preview documentation for this PR (at commit dee362d)

@sschildhauer
Copy link
Copy Markdown
Collaborator Author

I am a little confused with the warning/error I am getting here. It looks like there is a scoping issue relating to the base dataset when using dplyr, but when I fix the issue the tests are producing a warning. It seems like the solution might be in conflicting with each other. Grateful for any help!

@sschildhauer
Copy link
Copy Markdown
Collaborator Author

Hi Ezra and Kwan. I checked the snaps and having a hard time finding a solution. It looks like the test for print.sr_model in the github review is producing different median values than when I run the function locally. There also seems to be something going on with autoplot.case_data documention -- this is a new issue and has me stumped as well. Thank you so much for review. These should almost be there!

Copy link
Copy Markdown
Collaborator

@d-morrison d-morrison left a comment

Choose a reason for hiding this comment

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

@sschildhauer re: the document error: ggplot2 recently updated to v4.0 and changed a lot of stuff, including documentation, which the documentation for autoplot.case_data() depends on.

Please update ggplot2 and its dependencies on your local machine and re-run document(); once you do that, the changes you introduced in autoplot.case_data.Rd will hopefully go away.

@d-morrison
Copy link
Copy Markdown
Collaborator

d-morrison commented Oct 2, 2025

@sschildhauer PS - I bet updating ggplot2 will also resolve the snapshot discrepancies; feel free to re-ping me if you're still stuck after that.

@sschildhauer
Copy link
Copy Markdown
Collaborator Author

@Kwan-Jenny , can you also take a quick look at this when you get a chance? I recently created an option in the print to make the output similar to that of print.tbl_df.

sschildhauer and others added 6 commits October 26, 2025 17:31
Co-authored-by: Kwan-Jenny <68584166+Kwan-Jenny@users.noreply.github.com>
Merge commit 'fcdeafb1bf63c03cdeb86504ad1235ecf179ffb7'

#Conflicts:
#	DESCRIPTION
#	NEWS.md
#	R/expect_snapshot_data.R
#	inst/WORDLIST
Copilot AI review requested due to automatic review settings March 30, 2026 03:18
Copy link
Copy Markdown
Contributor

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

Adds an S3 print() method for sr_model objects (the primary output type of run_mod()), with snapshot tests and documentation, and surfaces the method in pkgdown.

Changes:

  • Introduces print.sr_model() with an option to print either a median-summary table or the underlying tibble.
  • Adds snapshot tests + snapshot outputs for the new print behavior.
  • Updates documentation/indexing (NAMESPACE, Rd, pkgdown reference) and project metadata (NEWS, WORDLIST).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
R/print.sr_model.R New S3 print method for sr_model including a summary view and a “print as tibble” option.
tests/testthat/test-print.sr_model.R Adds snapshot tests covering printed output for sr_model.
tests/testthat/_snaps/print.sr_model.md Snapshot expectations for the new print outputs.
man/print.sr_model.Rd Roxygen-generated documentation for print.sr_model.
NAMESPACE Registers print.sr_model as an S3 method.
pkgdown/_pkgdown.yml Adds print.sr_model to the reference index.
NEWS.md Changelog entry for the new print method.
inst/WORDLIST Adds new spelling whitelist terms.
R/Run_Mod.R Minor formatting-only change at end of file.

Comment on lines +1 to +13
test_that(
desc = "results are consistent with printed output for sr_model class",
code = {
testthat::expect_snapshot(nepal_sees_jags_output)
}
)

test_that(
desc = "results are consistent with printed output for sr_model class as tbl",
code = {
testthat::expect_snapshot(print(nepal_sees_jags_output, print_tbl = TRUE))
}
)
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The print method has logic to drop the Stratification column when it’s missing or all "None", but the added snapshot tests only cover stratified data (typhi/paratyphi). Add a test case for an sr_model with Stratification == "None" to exercise this branch and prevent regressions.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +27 to +33
x <- x |>
dplyr::summarise(.by = c(.data$Stratification, .data$Iso_type,
.data$Parameter),
median_val = stats::median(.data$value)) |>
tidyr::pivot_wider(names_from = .data$Parameter,
values_from = .data$median_val) |>
dplyr::arrange(.data$Iso_type) |>
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The printed summary is currently computed across all Subject values. Since sr_model contains subject-specific parameter draws, aggregating without filtering (e.g., to Subject == "newperson") produces a mixture that depends on how many subjects are in the object and is inconsistent with post_summ() / diagnostic helpers that summarise only newperson draws.

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +30
cat("An sr_model with the following median values:")
cat("\n")
cat("\n")
x <- x |>
dplyr::summarise(.by = c(.data$Stratification, .data$Iso_type,
.data$Parameter),
median_val = stats::median(.data$value)) |>
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The PR description says the default print shows the mean of the posterior distribution, but the implementation/message and docs use the median (stats::median() and "median values"). Please align the implementation, printed wording, and documentation with the intended statistic.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +10
#' @param print_tbl A [logical] indicator to print in style of [dplyr::tbl_df].
#' @param ... Additional arguments affecting the summary produced.
#' [serodynamics::run_mod()] function.
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

... is documented as affecting the summary produced by run_mod(), but this is a print method and ... is not used/forwarded. Consider documenting ... as additional arguments passed to print() (and actually pass ... through), or remove it if intentionally unused.

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +23
if (print_tbl) {
x <- dplyr::as_tibble(x)
print(x)
} else {
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

In the print_tbl = TRUE branch, the method converts x to a tibble and returns the result of print(x) (visible) without invisible(). For S3 print() methods, it’s conventional to return the original object invisibly; also consider not overwriting/dropping the sr_model class just for printing.

Copilot uses AI. Check for mistakes.
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