refactor(statmodel): Finalize namespaces for comparisons components#131
refactor(statmodel): Finalize namespaces for comparisons components#131tonywu1999 merged 3 commits intodevelfrom
Conversation
WalkthroughRefactors server module, UI components, and tests to use Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Failed to generate code suggestions for PR |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
R/module-statmodel-server.R (1)
77-82: Input validation correctly switched to namespaced IDs; consider also validating nameThe same-group and weight-sum checks now use the namespaced pairwise and non-pairwise weight inputs, so they track ID changes via
NAMESPACE_STATMODEL. You might additionally validate that the custom non-pairwise name is non-empty now that it’s a free textInput.- } else if (contrast_mode == CONSTANTS_STATMODEL$comparison_mode_custom_nonpairwise) { - wt_sum = sum(sapply(1:length(condition_list), function(i) { - input[[paste0(NAMESPACE_STATMODEL$comparisons_custom_nonpairwise_weights, i)]] - })) - - validate( - need(wt_sum == 0, "The contrast weights should sum up to 0") - ) - } + } else if (contrast_mode == CONSTANTS_STATMODEL$comparison_mode_custom_nonpairwise) { + validate( + need( + nzchar(input[[NAMESPACE_STATMODEL$comparisons_custom_nonpairwise_name]]), + "Please provide a comparison name" + ) + ) + + wt_sum = sum(sapply(1:length(condition_list), function(i) { + input[[paste0(NAMESPACE_STATMODEL$comparisons_custom_nonpairwise_weights, i)]] + })) + + validate( + need(wt_sum == 0, "The contrast weights should sum up to 0") + ) + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
R/module-statmodel-server.R(5 hunks)R/statmodel-ui-comparisons.R(1 hunks)tests/testthat/test-module-statmodel-server.R(7 hunks)tests/testthat/test-utils-statmodel-server.R(7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (23)
R/statmodel-ui-comparisons.R (1)
75-76: Non-pairwise name textInput wiring looks correctUsing
ns(NAMESPACE_STATMODEL$comparisons_custom_nonpairwise_name)here matches the server and test expectations and keeps the comparison-name input consistent with the new namespacing scheme.tests/testthat/test-utils-statmodel-server.R (8)
62-64: Pairwise util test now mirrors namespaced inputsInitializing
inputwithcomparisons_custom_pairwise_choice1/2viaNAMESPACE_STATMODELkeeps thebuild_custom_pairwise_contrasttest aligned with the server’s expected input shape.
83-85: Multiple-comparison pairwise test uses correct namespaced IDsThe second pairwise test also correctly switches to
comparisons_custom_pairwise_choice1/2keys, so it will keep tracking any future ID changes throughNAMESPACE_STATMODEL.
105-107: Same-group guard test wired to namespaced pairwise inputsUsing the same namespaced choice keys for the “same groups” case ensures this test exercises the same path as the runtime validation logic.
127-131: Non-pairwise contrast creation test correctly sets weights and namePopulating weights via
paste0(NAMESPACE_STATMODEL$comparisons_custom_nonpairwise_weights, i)and the name viacomparisons_custom_nonpairwise_namematches the server’s expected contract forbuild_custom_non_pairwise_contrast.
149-153: Non-zero-sum rejection test is consistent with new weight/name IDsThe invalid-weights case now also uses the namespaced weight keys and comparison name, so it accurately validates the behavior of
build_custom_non_pairwise_contrastwith the refactored inputs.
173-176: All-vs-one util test uses namespaced choice IDSetting
comparisons_all_vs_one_choicethroughNAMESPACE_STATMODELkeeps this test aligned withbuild_all_against_one_contrastand the new UI wiring.
195-196: Single-comparison all-vs-one test also updated to namespaced IDThe single-comparison variant correctly uses
comparisons_all_vs_one_choiceas well, so both all-vs-one utility tests share the same namespaced contract.
369-372: get_contrast_panel_ui test now checks for new non-pairwise IDsAsserting that the rendered HTML contains
comparisons_custom_nonpairwise_nameandcomparisons_custom_nonpairwise_weightsensures the non-pairwise panel exposes the expected namespaced controls.tests/testthat/test-module-statmodel-server.R (7)
192-193: Pairwise matrix_build test correctly switches to namespaced choicesUsing
comparisons_custom_pairwise_choice1/2here matchesrender_custom_pairwise_inputsandbuild_custom_pairwise_contrast, so this test will stay in sync with the refactored server logic.
283-284: All-vs-one matrix_build test uses the correct choice keySetting
comparisons_all_vs_one_choiceviaNAMESPACE_STATMODELis consistent withrender_all_against_one_inputsandbuild_all_against_one_contrast.
326-329: Custom non-pairwise matrix_build test matches server expectationsThe test now sets the comparison name and each weight using the same namespaced IDs that
render_custom_non_pairwise_inputs,validate_contrast_inputs, andbuild_custom_non_pairwise_contrastread from, so the flow is fully covered.
377-379: Same-group validation test aligned with namespaced pairwise IDsUsing
comparisons_custom_pairwise_choice1/2here ensurescheck_cond()exercises the same validation path as the production UI when identical groups are selected.
415-418: Non-zero-sum validation test wired to namespaced non-pairwise IDsThe “BadComparison” case now drives
check_cond()through the namespaced non-pairwise name and weight inputs, accurately reflecting the new input schema.
455-456: Mode-change reset test uses namespaced pairwise choicesBuilding the initial matrix with
comparisons_custom_pairwise_choice1/2keeps this reset test consistent with the rest of the contrast-building pipeline.
500-501: Duplicate-row guard test uses namespaced pairwise IDsBoth submissions in the duplicate-row test now use the namespaced pairwise choice IDs, so it continues to validate deduplication after the refactor.
R/module-statmodel-server.R (7)
44-45: All-vs-one selectInput now correctly uses namespaced choice ID
selectInput(ns(NAMESPACE_STATMODEL$comparisons_all_vs_one_choice), ...)matches the UI (build_all_vs_one_panel) and server readers, so the all-vs-one target group is consistently namespaced.
52-57: Custom pairwise selectInputs are properly namespacedBoth “Group 1” and “Group 2” selectors now use
comparisons_custom_pairwise_choice1/2throughns(), aligning withbuild_custom_pairwise_contrastand the updated tests.
64-67: Non-pairwise weight inputs use consistent namespaced patternGenerating numeric inputs with IDs
paste0(NAMESPACE_STATMODEL$comparisons_custom_nonpairwise_weights, i)matches how validation and matrix-building later read the weights and what tests expect.
91-100: Pairwise contrast builder now fully driven by namespaced inputsThe equality guard, index lookups, and label construction all read from
comparisons_custom_pairwise_choice1/2, which is consistent with the UI and tests and avoids any stray hard-coded IDs.
119-133: Non-pairwise contrast builder uses namespaced weights and name
build_custom_non_pairwise_contrastnow computes the weight sum, row entries, and rownames from the same namespaced keys used in the UI and tests, so the whole path is coherent after the refactor.
149-156: All-vs-one contrast builder reads choice via namespaced IDUsing
input[[NAMESPACE_STATMODEL$comparisons_all_vs_one_choice]]both forindex3and label construction lines this helper up withrender_all_against_one_inputsand the tests for all-vs-one contrasts.
462-535: Server wiring for contrast mode and actions consistently uses NAMESPACE_STATMODEL IDsThe conditional panel,
Rownames,check_cond,matrix_build, and the clear-observer now all depend on the same namespaced comparison mode and submit/clear IDs as the UI and tests. This removes the previous hard-coded input names and centralizes all IDs underNAMESPACE_STATMODEL, which should make future renames much safer.
Summary by CodeRabbit
UI Changes
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.