-
Notifications
You must be signed in to change notification settings - Fork 69
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
dispo var functions #123
Merged
+294
−76
Merged
dispo var functions #123
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
77b920e
dispo var functions
bfaed88
Merge branch 'master' into 91_disposition_var
kabis-ops 07b94c9
dispo var
kabis-ops 327a2da
Merge branch '91_disposition_var' of https://github.com/Roche-GSK/adm…
kabis-ops e2b3380
expr-exprs
kabis-ops 5a6f21a
Merge branch '91_disposition_var' of https://github.com/Roche-GSK/adm…
kabis-ops 731397b
option to discuss
kabis-ops 8cadb21
general functions
kabis-ops 58c78b9
91_disposition_dates
kabis-ops 4f79f26
Merge branch 'develop' into 91_disposition_var
403816d
91_disposition_dates: update after review
kabis-ops e1deb23
91_disposition_var
kabis-ops 4678116
91_disposition_var
kabis-ops 1133170
Merge branch '91_disposition_var' of https://github.com/Roche-GSK/adm…
kabis-ops bfb69b3
91_disposition_var: update after review
kabis-ops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#' Derive a disposition date | ||
#' | ||
#' Derive a disposition status date from the the relevant records in the disposition domain. | ||
#' | ||
#' @param dataset Input dataset | ||
#' | ||
#' @param dataset_ds Datasets containing the disposition information (e.g.: ds) | ||
#' | ||
#' The variable specified in dtc parameter must be in dataset_ds | ||
#' | ||
#' @param new_var Name of the disposition date variable | ||
#' | ||
#' a variable name is expected | ||
#' | ||
#' @param dtc The character date used to derive/impute the disposition date | ||
#' | ||
#' A character date is expected in a format like yyyy-mm-dd or yyyy-mm-ddThh:mm:ss. | ||
#' If the year part is not recorded (missing date), no imputation is performed. | ||
#' | ||
#' @param filter_ds Filter condition for the disposition data. | ||
#' | ||
#' Filter used to select the relevant disposition data. | ||
#' | ||
#' Permitted Values: logical expression | ||
#' | ||
#' @param date_imputation The value to impute the day/month when a datepart is missing. | ||
#' | ||
#' If NULL: no date imputation is performed and partial dates are returned as missing. | ||
#' | ||
#' Otherwise, a character value is expected, either as a | ||
#' - format with day and month specified as 'dd-mm': e.g. '15-06' for the 15th of June | ||
#' - or as a keyword: 'FIRST', 'MID', 'LAST' to impute to the first/mid/last day/month | ||
#' | ||
#' Default is NULL | ||
#' | ||
#' @return the input dataset with the disposition date (new_var) added | ||
#' | ||
#' @keywords adsl timing | ||
#' | ||
#' @author Samia Kabi | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' data("dm") | ||
#' data("ds") | ||
#' derive_disposition_dt( | ||
#' dataset = dm, | ||
#' dataset_ds = ds, | ||
#' new_var = FRVDT, | ||
#' dtc = DSSTDTC, | ||
#' filter = expr(DSCAT == "OTHER EVENT" & DSDECOD == "FINAL RETRIEVAL VISIT") | ||
#' ) | ||
derive_disposition_dt <- function(dataset, | ||
dataset_ds, | ||
new_var, | ||
dtc, | ||
filter_ds, | ||
date_imputation = NULL) { | ||
# Checks | ||
warn_if_vars_exist(dataset, deparse(substitute(new_var))) | ||
assert_that(is.data.frame(dataset_ds)) | ||
assert_has_variables(dataset_ds, deparse(substitute(dtc))) | ||
|
||
# Process the disposition data | ||
prefix <- sub("\\DT.*", "", deparse(substitute(new_var))) | ||
newvar <- paste0(prefix, "DT") | ||
ds_subset <- dataset_ds %>% | ||
filter(!!filter_ds) %>% | ||
mutate(datedtc___ = !!enquo(dtc)) %>% | ||
derive_vars_dt( | ||
new_vars_prefix = prefix, | ||
dtc = datedtc___, | ||
date_imputation = date_imputation, | ||
flag_imputation = FALSE | ||
) %>% | ||
select(STUDYID, USUBJID, !!enquo(new_var) := !!sym(newvar)) | ||
|
||
# Expect 1 record per subject - issue a warning otherwise | ||
has_unique_records( | ||
dataset = ds_subset, | ||
by_vars = "USUBJID", | ||
message_type = "warning", | ||
message = "the filter used for DS results in several records per patient - please check" | ||
) | ||
|
||
# add the new dispo date to the input dataset | ||
dataset %>% | ||
left_join(ds_subset, by = c("STUDYID", "USUBJID")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please include
in the example to make the loading of the data explicit.
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.
Unfortunately our example data doesn't contain records where
DSCAT == "PROTOCOL MILESTONE" & DSDECOD == "INFORMED CONSENT OBTAINED"
. Please update such that the example actually runs on the example data.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.
ok