-
Notifications
You must be signed in to change notification settings - Fork 8
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
253 feature request deprecatesupersede derive vars crit #254
base: main
Are you sure you want to change the base?
Changes from 2 commits
ec72fdd
19f3c2a
08353a7
ea1ae6c
6c132ba
6b0196e
85e7128
6c8f043
158a507
15e74e7
9e97389
5a9571c
e5d41e3
5623e15
09c2f16
6b660f6
5e43e5e
7a62636
76d8802
69f98dd
f5e454e
fc814f2
46ef0db
8ec9bf1
72f8481
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,145 +2,12 @@ | |
#' | ||
#' | ||
#' @description | ||
#' Derive analysis criterion evaluation result variable, paired with character | ||
#' and numeric flags. | ||
#' This function allows also the derivation of a CRIT like variable with a | ||
#' different name (ex: `ANL01FL`), without generating additional numeric (ex: `ANL01FN`) | ||
#' and character label (ex: `ANL01`) variables. | ||
#' `r derive_vars_crit::admiralvaccine("deprecated")` | ||
#' | ||
#' @param dataset Input dataset | ||
#' This function is *deprecated*, please use `derive_vars_crit_flag` instead. | ||
#' | ||
#' . | ||
#' @family deprecated | ||
#' | ||
#' @param prefix Variables to add | ||
#' | ||
#' The analysis criterion evaluation variable's name (i.e., `CRIT1`) | ||
#' This name is also used in order to create both character and numeric | ||
#' flags variables (i.e., `CRIT1FL` and `CRIT1FN`). | ||
#' If the name does not contain CRIT wording, it generates a flag variable | ||
#' (ex: `ANL01FL`) whose logic is equals to `CRIT1` variable, without generating | ||
#' additional numeric (ex: `ANL01FN`) and character (`ANL01`) variables. | ||
#' | ||
#' | ||
#' @param crit_label Criterion value | ||
#' | ||
#' A text description defining the condition necessary to satisfy the presence | ||
#' of the criterion | ||
#' | ||
#' | ||
#' @param condition Condition for selecting a subset | ||
#' | ||
#' The condition specified in order to select a subset from the input dataset | ||
#' in which the rule is applied. | ||
#' | ||
#' | ||
#' @param criterion Criterion rule | ||
#' | ||
#' The criterion that each selected row satisfies or not. | ||
#' Returns `Y` or `N` for character variable and `1` or `0` for numeric variable | ||
#' if the criterion is met or not, respectively. | ||
#' Returns `NA` for not selected rows (not taken into account from condition) | ||
#' | ||
#' | ||
#' @return Dataset with criterion variables | ||
#' | ||
#' @export | ||
#' | ||
#' @author Federico Baratin | ||
#' @export | ||
#' @keywords der_var | ||
#' @family der_var | ||
#' | ||
#' @examples | ||
#' library(tibble) | ||
#' library(admiral) | ||
#' library(admiraldev) | ||
#' library(dplyr) | ||
#' | ||
#' input <- tribble( | ||
#' ~USUBJID, ~AVISITN, ~ISCAT, ~PARAMCD, ~AVAL, ~ISLLOQ, | ||
#' "999999-000001", 10, "IMMUNOLOGY", "J0033VN", 2, 4, | ||
#' "999999-000001", 10, "IMMUNOLOGY", "I0019NT", 3, 6, | ||
#' "999999-000001", 10, "IMMUNOLOGY", "M0019LN", 4, 4, | ||
#' "999999-000001", 10, "IMMUNOLOGY", "R0003MA", 3, 6, | ||
#' "999999-000001", 30, "IMMUNOLOGY", "J0033VN", 60, 4, | ||
#' "999999-000001", 30, "IMMUNOLOGY", "I0019NT", 567, 6, | ||
#' "999999-000001", 30, "IMMUNOLOGY", "M0019LN", 659, 4, | ||
#' "999999-000001", 30, "IMMUNOLOGY", "R0003MA", 250, 6, | ||
#' "999999-000002", 10, "IMMUNOLOGY", "J0033VN", 2, 4, | ||
#' "999999-000002", 10, "IMMUNOLOGY", "I0019NT", 7, 6, | ||
#' "999999-000002", 10, "IMMUNOLOGY", "M0019LN", 5, 4, | ||
#' "999999-000002", 10, "IMMUNOLOGY", "R0003MA", 3, 6, | ||
#' "999999-000002", 30, "IMMUNOLOGY", "J0033VN", 55, 4, | ||
#' "999999-000002", 30, "IMMUNOLOGY", "I0019NT", 89, 6, | ||
#' "999999-000002", 30, "IMMUNOLOGY", "M0019LN", 990, 4, | ||
#' "999999-000002", 30, "IMMUNOLOGY", "R0003MA", 340, 6, | ||
#' "999999-000003", 10, "IMMUNOLOGY", "J0033VN", 3, 4, | ||
#' "999999-000003", 10, "IMMUNOLOGY", "I0019NT", 6, 6, | ||
#' "999999-000003", 10, "IMMUNOLOGY", "M0019LN", 2, 4, | ||
#' "999999-000003", 10, "IMMUNOLOGY", "R0003MA", 2, 6, | ||
#' "999999-000003", 30, "IMMUNOLOGY", "J0033VN", 45, 4, | ||
#' "999999-000003", 30, "IMMUNOLOGY", "I0019NT", 381, 6, | ||
#' "999999-000003", 30, "IMMUNOLOGY", "M0019LN", 542, 4, | ||
#' "999999-000003", 30, "IMMUNOLOGY", "R0003MA", NA, 6 | ||
#' ) | ||
#' | ||
#' | ||
#' derive_vars_crit( | ||
#' dataset = input, | ||
#' prefix = "CRIT1", | ||
#' crit_label = "Titer >= ISLLOQ", | ||
#' condition = !is.na(AVAL) & !is.na(ISLLOQ), | ||
#' criterion = AVAL >= ISLLOQ | ||
#' ) | ||
#' | ||
derive_vars_crit <- function(dataset, prefix, crit_label, condition, criterion) { | ||
condition <- assert_filter_cond(enquo(condition)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not in line with our deprecation strategy. Here you have deleted all the function code and just added a warning. So the function behaves completely differently to before, as it is essentially just a warning thrower. If I am using this function in any code and upversion admiralvaccine, now my code will error or at least not derive the variables. Instead, what we want is for the code to still work, but a warning to be thrown (at least for this 1st Phase of deprecation, see again here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Edoardo, I can take it. Just one question: on the Phase 1 strategy is suggested to put a warning + replace the "old" function code with the new one. Is this also the case? Or, for the moment, a simple warning + "old" function code is needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as you are implementing phase 1, you should just add the warning at the top of the function and then keep all else the same. you should also not delete documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just to add, in your case you don't have any actual new code to replace as you are just deprecating this function in favour of one from another package (admiral) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hi @manciniedoardo Thanks for the review! We have removed the old code and replaced it with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks! I have just updated the documentation as per suggestions. @ahasoplakus , I kept the warning you put at the top of the function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ahasoplakus . I just seen that you are working on that. I made a couple of simple updates, so I would stop here just to avoid confusion. Please, let me know if any change is required from my side There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks @federicobaratin Please feel free to go ahead with the changes @manciniedoardo suggested and fix the checks that are currently failing. I will do a final review and merge |
||
criterion <- assert_filter_cond(enquo(criterion)) | ||
|
||
var_char <- paste0(prefix, "FL") | ||
var_num <- paste0(prefix, "FN") | ||
|
||
if (grepl("CRIT", prefix)) { | ||
data <- dataset %>% | ||
mutate( | ||
`:=`( | ||
!!var_char, | ||
case_when( | ||
!(!!condition) ~ NA_character_, | ||
!!criterion & !!condition ~ "Y", | ||
!(!!criterion) & !!condition ~ "N" | ||
) | ||
), | ||
`:=`( | ||
!!var_num, | ||
case_when( | ||
!(!!condition) ~ NA_real_, | ||
!!criterion & !!condition ~ 1, | ||
!(!!criterion) & !!condition ~ 0 | ||
) | ||
), | ||
`:=`( | ||
!!prefix, | ||
case_when( | ||
!(!!condition) ~ NA_character_, | ||
!!criterion & !!condition ~ crit_label, | ||
!(!!criterion) & !!condition ~ crit_label | ||
) | ||
) | ||
) | ||
} else { | ||
data <- dataset %>% | ||
mutate( | ||
`:=`( | ||
!!var_char, | ||
case_when( | ||
!(!!condition) ~ NA_character_, | ||
!!criterion & !!condition ~ "Y", | ||
!(!!criterion) & !!condition ~ "N" | ||
) | ||
) | ||
) | ||
} | ||
|
||
return(data) | ||
} | ||
#' @keywords deprecated | ||
#' . | ||
ahasoplakus marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
why delete this section? i think ok to keep, just need to add the badge.