Skip to content

feat: implement knit_print methods for Simulations classes#931

Open
pengguanya wants to merge 14 commits intomainfrom
930-implement-knit-print-for-subclasses-of-simulations
Open

feat: implement knit_print methods for Simulations classes#931
pengguanya wants to merge 14 commits intomainfrom
930-implement-knit-print-for-subclasses-of-simulations

Conversation

@pengguanya
Copy link
Collaborator

Pull Request

Implements knit_print S3 methods for all Simulations and SimulationsSummary subclasses to enable human-friendly rendering in Markdown and Quarto documents.

Classes implemented:

  • GeneralSimulations
  • Simulations
  • DualSimulations
  • PseudoSimulations
  • PseudoDualSimulations
  • PseudoDualFlexiSimulations
  • DASimulations
  • GeneralSimulationsSummary
  • SimulationsSummary
  • DualSimulationsSummary
  • PseudoSimulationsSummary
  • PseudoDualSimulationsSummary

Fixes #930

Implements knit_print S3 methods for all Simulations and SimulationsSummary
subclasses to enable human-friendly rendering in Markdown and Quarto documents.

Classes implemented:
- GeneralSimulations
- Simulations
- DualSimulations
- PseudoSimulations
- PseudoDualSimulations
- PseudoDualFlexiSimulations
- DASimulations
- GeneralSimulationsSummary
- SimulationsSummary
- DualSimulationsSummary
- PseudoSimulationsSummary
- PseudoDualSimulationsSummary

Closes #930
@pengguanya pengguanya self-assigned this Jan 27, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
CrmPackClass-class 💚 $2.65$ $-1.61$ $0$ $0$ $0$ $0$
Design-methods 💚 $89.82$ $-2.59$ $0$ $0$ $0$ $0$
Rules-methods 💚 $40.53$ $-2.16$ $0$ $0$ $0$ $0$
helpers_knitr 💚 $29.64$ $-15.92$ $+21$ $-1$ $0$ $+1$
helpers_knitr_Simulations 👶 $+0.42$ $+36$ $+12$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
CrmPackClass-class 💚 $2.51$ $-1.62$ CrmPackClass_correctly_identifies_crmPack_classes
helpers_knitr 💚 $19.62$ $-15.51$ knit_print_methods_exist_for_all_relevant_classes_and_produce_consistent_output
helpers_knitr_Simulations 👶 $+0.02$ knit_print.DASimulations_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.01$ knit_print.DASimulations_works_correctly
helpers_knitr_Simulations 👶 $+0.02$ knit_print.DualSimulationsSummary_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.01$ knit_print.DualSimulationsSummary_works_correctly
helpers_knitr_Simulations 👶 $+0.02$ knit_print.DualSimulations_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.02$ knit_print.DualSimulations_works_correctly
helpers_knitr_Simulations 👶 $+0.02$ knit_print.GeneralSimulationsSummary_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.01$ knit_print.GeneralSimulationsSummary_works_correctly
helpers_knitr_Simulations 👶 $+0.02$ knit_print.GeneralSimulations_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.02$ knit_print.GeneralSimulations_works_correctly
helpers_knitr_Simulations 👶 $+0.03$ knit_print.PseudoDualFlexiSimulations_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.02$ knit_print.PseudoDualFlexiSimulations_works_correctly
helpers_knitr_Simulations 👶 $+0.02$ knit_print.PseudoDualSimulationsSummary_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.01$ knit_print.PseudoDualSimulationsSummary_works_correctly
helpers_knitr_Simulations 👶 $+0.02$ knit_print.PseudoDualSimulations_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.02$ knit_print.PseudoDualSimulations_works_correctly
helpers_knitr_Simulations 👶 $+0.02$ knit_print.PseudoSimulationsSummary_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.01$ knit_print.PseudoSimulationsSummary_works_correctly
helpers_knitr_Simulations 👶 $+0.02$ knit_print.PseudoSimulations_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.02$ knit_print.PseudoSimulations_works_correctly
helpers_knitr_Simulations 👶 $+0.02$ knit_print.SimulationsSummary_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.01$ knit_print.SimulationsSummary_works_correctly
helpers_knitr_Simulations 👶 $+0.01$ knit_print.Simulations_handles_asis_parameter
helpers_knitr_Simulations 👶 $+0.01$ knit_print.Simulations_works_correctly

Results for commit b3621a6

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

badge

Code Coverage Summary

Filename                          Stmts    Miss  Cover    Missing
------------------------------  -------  ------  -------  ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
R/checkmate.R                       100       2  98.00%   72, 462
R/crmPack-package.R                   4       0  100.00%
R/CrmPackClass-methods.R              5       0  100.00%
R/Data-class.R                      160       7  95.62%   43-45, 576-577, 583-588
R/Data-methods.R                    296       0  100.00%
R/Data-validity.R                   196       1  99.49%   21
R/Design-class.R                    401       0  100.00%
R/Design-methods.R                 2917     294  89.92%   457-461, 473-481, 486, 744-748, 751-757, 759, 768, 771-778, 1389-1398, 1426, 1470-1471, 1724-1728, 1735-1746, 1749-1760, 1764-1797, 1814-1823, 1829-1844, 2220-2231, 2234-2245, 2249-2283, 2367, 2418-2419, 2812, 2814-2815, 2891, 3004-3015, 3026, 3052-3056, 3151-3195, 3199-3202, 3207-3213, 3246, 3260-3279, 3535, 3866-3870, 3976, 3990-3994, 4050, 4199, 4306
R/Design-validity.R                  42      14  66.67%   51-64
R/fromQuantiles.R                   189       0  100.00%
R/helpers_broom.R                    77      10  87.01%   33, 37-38, 40-41, 43, 87, 108-110
R/helpers_covr.R                     25       0  100.00%
R/helpers_data.R                     96       1  98.96%   140
R/helpers_design.R                  136      35  74.26%   78-130
R/helpers_jags.R                     83       0  100.00%
R/helpers_knitr_CohortSize.R        119       0  100.00%
R/helpers_knitr_Design.R            355      14  96.06%   24-29, 330-337
R/helpers_knitr_GeneralData.R       220      41  81.36%   128-131, 148-151, 189-191, 274-278, 287-310, 325-330, 383
R/helpers_knitr_GeneralModel.R      858       3  99.65%   110, 466, 982
R/helpers_knitr_Increments.R        181       0  100.00%
R/helpers_knitr_NextBest.R          325       0  100.00%
R/helpers_knitr_SafetyWindow.R      155       1  99.35%   109
R/helpers_knitr_Simulations.R       250      88  64.80%   265-288, 325, 364, 394-512
R/helpers_knitr_Stopping.R          270       0  100.00%
R/helpers_knitr.R                    28       0  100.00%
R/helpers_model.R                    85       4  95.29%   40, 89-90, 141
R/helpers_rules.R                   532       0  100.00%
R/helpers_samples.R                   8       0  100.00%
R/helpers_simulations.R              27       0  100.00%
R/helpers.R                         239      35  85.36%   177-194, 225-268, 388-406
R/logger.R                           11       0  100.00%
R/mcmc.R                            310      17  94.52%   88-93, 354-355, 364-366, 369-372, 560-561, 662, 718
R/McmcOptions-class.R                22       0  100.00%
R/McmcOptions-methods.R               8       1  87.50%   43
R/McmcOptions-validity.R             42       0  100.00%
R/Model-class.R                    1146     181  84.21%   147-149, 221-223, 227-229, 291-293, 365-367, 371-373, 455-457, 524-526, 591-595, 598-601, 706-712, 716-717, 843-847, 964-966, 970-978, 1126-1128, 1133-1136, 1140-1143, 1260-1264, 1266-1269, 1273-1276, 1279, 1443-1457, 1462-1468, 1623-1626, 1632-1640, 1792, 1801, 1810, 1819, 1828-1837, 1969, 1978, 1987, 1995-1998, 2847-2876, 2881-2890, 2897-2901, 2906, 3036-3049, 3076, 3184-3186, 3190, 3290-3292, 3296, 3367-3379, 3398, 3463-3465, 3467-3468, 3471-3476
R/Model-methods.R                   557      44  92.10%   83, 246-254, 841-886, 1213-1225
R/Model-validity.R                  545      16  97.06%   485-488, 497-500, 703-711
R/ModelParams-class.R                17       0  100.00%
R/ModelParams-validity.R             26       0  100.00%
R/Rules-class.R                     524       0  100.00%
R/Rules-methods.R                  2063     274  86.72%   1174-1180, 1190-1196, 1206, 1358-1364, 1374-1380, 1386, 1515-1518, 1550, 1667-1670, 1702, 2235, 3158-3170, 3195-3205, 3370-3379, 3583-3878, 4466, 4470
R/Rules-validity.R                  543      36  93.37%   391-396, 788-827
R/Samples-class.R                     6       0  100.00%
R/Samples-methods.R                1158       4  99.65%   1635-1636, 1668, 1681
R/Samples-validity.R                 10       0  100.00%
R/Simulations-class.R               227       1  99.56%   1013
R/Simulations-methods.R            1576     152  90.36%   51, 95, 174-180, 318, 326-330, 402-419, 432-437, 482-491, 732, 735, 830-847, 858-867, 959-967, 1100-1105, 1128-1134, 2336-2339, 2441-2444, 2529-2533, 2585, 2905-2955
R/Simulations-validity.R             76       0  100.00%
R/utils.R                             6       0  100.00%
TOTAL                             17252    1276  92.60%

Diff against main

Filename                         Stmts    Miss  Cover
-----------------------------  -------  ------  -------
R/helpers_knitr_Simulations.R     +250     +88  +64.80%
R/Simulations-class.R                0     -60  +26.43%
TOTAL                             +250     +28  -0.06%

Results for commit: 8917857

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

Unit Tests Summary

    1 files     55 suites   4m 31s ⏱️
1 598 tests 1 429 ✅ 168 💤 0 ❌ 1 🔥
7 525 runs  7 288 ✅ 236 💤 0 ❌ 1 🔥

For more details on these errors, see this check.

Results for commit e62ee9d.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@danielinteractive danielinteractive left a comment

Choose a reason for hiding this comment

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

Thanks @pengguanya , please see couple of comments below.
Please can you also check that

  • the representation in rmd / qmd files looks "good"
  • the help page knit_print looks "good"

# DualSimulationsSummary ----

test_that("knit_print.DualSimulationsSummary works correctly", {
skip("DualSimulations summary requires complex setup with biomarker truth")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and below we also need real tests. If it takes too long to run simulations here you can follow the pattern used for the other mock simulation objects, see https://github.com/openpharma/crmPack/blob/main/tests/testthat/test-CrmPackClass-class.R

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@danielinteractive Updated. Please review again.


result <- knit_print(x, asis = FALSE)

expect_true(grepl("### Simulation Results", result, fixed = TRUE))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of checking for these strings I would prefer snapshot tests such that I can see how the results look like (see as reference https://github.com/openpharma/crmPack/tree/main/tests/testthat/_snaps/Darwin/helpers_knitr where we have a lot of other snapshots already saved)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not done yet. will take more time.

@danielinteractive
Copy link
Collaborator

Hi @pengguanya , I merged main into your branch, so you could continue from there

github-actions bot and others added 7 commits January 31, 2026 13:10
Convert string-based grepl() assertions to expect_snap() for deterministic
simulation objects (GeneralSimulations, DualSimulations, PseudoSimulations,
PseudoDualSimulations, PseudoDualFlexiSimulations).

Keep grepl() assertions for MCMC-dependent tests (Simulations, DASimulations,
Summary classes) to avoid brittle tests from stochastic variation.

Add platform-specific snapshot files for Linux, Darwin, and Windows.
Co-authored-by: Daniel Sabanes Bove <danielinteractive@users.noreply.github.com>
Replace 6 skipped tests with real tests using pre-computed RDS fixtures:
- DualSimulationsSummary
- PseudoSimulationsSummary
- PseudoDualSimulationsSummary

Also fix .DefaultDualSimulationsSummary() to throw an error for
consistency with other summary class constructors.
Convert grepl-based assertions to expect_snap() for better visibility
of knit_print output as requested in code review.
- Convert grepl-based tests to expect_snap() for consistency:
  - knit_print.Simulations
  - knit_print.DASimulations
  - knit_print.GeneralSimulationsSummary
  - knit_print.SimulationsSummary
- Add mocks for .DefaultSimulations, .DefaultDASimulations,
  and .DefaultSimulationsSummary to ensure stable snapshots
- Add SimulationsSummary fixture generation
- Regenerate all fixtures for consistency
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.

Implement knit_print for subclasses of Simulations (including tests)

2 participants