new unified get_ref_info - #423
Conversation
|
Hi @munoztd0 - I slightly streamlined the code. |
| trt_var = ref_path_last[1L], | ||
| ctrl_grp = ref_path_last[2L], |
There was a problem hiding this comment.
why the name trt_var / ctrl_grp ? It does not need to be treatment var or control group, I think.
gmbecker
left a comment
There was a problem hiding this comment.
Overall looks good, some small tweaks/additions to the tests/documentation.
Also, a good way to cover something like this is to make a table where the cell values are/represent the info you want to check (in this case what comes out of get_ref_info,
So we could use
introspect_ref_info <- function(df, ref_path, .spl_context) {
refinfo <- get_ref_info(ref_path, .spl_context)
in_rows(trt_var = refinfo$trt_var,
ctrl_grp = refinfo$ctrl_grp,
ref_group_dim = dim(refinof$ref_group),
in_ref_col = refinfo$in_ref_col)
And then compare the table or the cell values to make our assertions. Also useful for documenting what get_ref_info does in various situations in a human readable way (e.g., in a vignette?)
| #' on `.var`), equivalent to `.ref_group` from [rtables::additional_fun_params]. | ||
| #' * `in_ref_col`: logical, whether the current column is the reference column, | ||
| #' equivalent to `.in_ref_col` from [rtables::additional_fun_params]. | ||
| #' * `trt_var`: the treatment variable name (last variable in `ref_path`). |
There was a problem hiding this comment.
technically this is the most recent split's name, which is usually a variable name from the data, but its not guaranteed to be
|
|
||
| build_table(lyt, dm) | ||
|
|
||
| expect_true(length(captured) >= 1L) |
There was a problem hiding this comment.
make this tests more specific to the exact length we expect it to be, especially since you are only capturing in risk diff cols here.
| } | ||
| }) | ||
|
|
||
| test_that("get_ref_info returns trt_var and ctrl_grp even when ref_path is outside colvars (risk-diff column)", { |
There was a problem hiding this comment.
colvars refers to when split_cols_by_multivar is used, so this description of the test is not accurate, though the test itself seems fine.
Pull Request
Fixes #295
Context
juncohas at 3 ways to resolve a reference group fromref_path+.spl_context:get_ref_info()exported, returnsref_group+in_ref_col, handles NULL cases. Used by mosta_*functions.h_get_trtvar_refpath()exported (should it even be export ?), returnstrt_var/ctrl_grponly, notref_group. Usestail(...,1)assumption on the split context.a_summarize_aval_chg_diff_jreimplements both above from scratch, with a differentref_groupconstruction strategy, (direct filter vs.spl_contextindex).Fix
Unified all into get_ref_info() and soft deprecated all the others.
Questions
Contributing
get_ref_infoto tern after we align all ?Checks