-
Notifications
You must be signed in to change notification settings - Fork 24
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
Interval support functions: add/remove impute (#379) #384
base: main
Are you sure you want to change the base?
Conversation
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.
I've not yet reviewed the tests since I requested some bigger changes in the other code.
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 move this to the test/testthat
directory.
@@ -0,0 +1,140 @@ | |||
library(testthat) |
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 remove the library()
lines as they are not needed in testthat
tests.
@@ -0,0 +1,244 @@ | |||
# Load necessary library | |||
library(dplyr) |
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 remove library()
from this file. If we need dplyr
functions, please use dplyr::function_name()
.
|
||
#' Remove specified imputation methods from the intervals in a PKNCAdata object. | ||
#' | ||
#' @param data A PKNCAdata object containing the intervals and data components. |
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 ensure that it can work either on a data.frame or on a PKNCAdata object. (Other comments will relate to this, too.)
#' @param data A PKNCAdata object containing the intervals and data components. | ||
#' @param target_impute A character string specifying the imputation method to be removed. | ||
#' @param target_params A character vector specifying the parameters to be targeted (optional). If missing, all TRUE in the intervals are taken. | ||
#' @param target_groups A named list specifying the intervals to be targeted (optional). If missing, all relevant groups are considered. |
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.
I like the concept of how you've implemented this. Please make this into a data.frame so that it can work more simply with the way people are accustomed to working with intervals.
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.
Hey! @DaTa will also be the intervals dataframe. I guess in this case we cannot guess the impute column always, sobwould need another arg
Indeed I think using a dataframe as an input would make a lot of sense also to match the intervals for the target_groups
arg, which we can call instead something like target_intervals
. Here is then an example:
If this is my initial interval table:
USUBJID | ANALYTE | cmax | tmax | aucinf.pred | impute |
---|---|---|---|---|---|
001 | Analyte1 | TRUE | TRUE | TRUE | start_predose |
I would then like to remove only for cmax and tmax the imputation, while keeping it for the other parameters:
interval_remove_impute(PKNCAdata$intervals,
target_impute = "start_predose",
target_params = c("cmax", "tmax"),
target_intervals = data.frame(ANALYTE="Analyte1") )
This produces:
USUBJID | ANALYTE | cmax | tmax | aucinf.pred | impute |
---|---|---|---|---|---|
001 | Analyte1 | FALSE | FALSE | TRUE | start_predose |
001 | Analyte1 | TRUE | TRUE | FALSE | NA |
That way we keep it intuitive: target_intervals
indicates the rows to be considered (even if it can also contain parameter or impute specifications) while target_params
the columns for which the removal applies.
#' @param target_impute A character string specifying the imputation method to be added. | ||
#' @param after Numeric value specifying the position after which the imputation method should be added (optional). First is 0, last Inf. If missing, the imputation method is added at the end (Inf). | ||
#' @param target_params A character vector specifying the parameters to be targeted (optional). If missing, all TRUE in the intervals are taken. | ||
#' @param target_groups A named list specifying the intervals to be targeted (optional). If missing, all relevant groups are considered. |
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 make this a data.frame and for it to work the same as in the other function.
#' print(o_data$intervals) | ||
#' | ||
#' @export | ||
interval_add_impute <- function(data, target_impute, after = Inf, target_params = NULL, target_groups = NULL) { |
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 make this S3 generic like the other function.
} | ||
|
||
# Get all parameter column names in the PKNCAdata object | ||
all_param_options <- names(sapply(PKNCA.options()$single.dose.aucs, is.logical)) |
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 use the same way of finding parameter names.
} else if ("impute" %in% colnames(data$intervals)) { | ||
"impute" | ||
} else { | ||
stop("The 'data$intervals' object must contain an impute column either defined in the PKNCAdata object or called `impute`.") |
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.
We should add the column for the user rather than giving an error if it doesn't exist.
} | ||
|
||
# Identify the targeted intervals to which the action is applied | ||
mask_target_rows <- data$intervals %>% |
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 simplify this code similar to the above with inner_join()
and anti_join()
.
Contributes to solve #379
New interval supporting functions acting to add/remove imputations from the impute column in
PKNCAdata$intervals
Add imputation
interval_add_impute(data, target_impute, after = Inf, target_params = NULL, target_groups = NULL)
impute is the imputation character string to add, matching the behavior of PKNCAdata()
after follows similar behavior to the after argument of base::append(); 0 indicates it will be added as the first imputation method; Inf (or any number greater than the number of methods currently specified) indicates that it will be added as the last imputation method;
If there is already an imputation:
the imputation will be separated by commas (i.e. strsplit(current_impute, split = "[, ]"))
the new imputation will be added at the correct place (defined by after), and
The final imputation method will be put back together separated by commas (i.e. vapply(X = new_impute, FUN = paste, collapse = ",", FUN.VALUE = ""))
Remove imputation
interval_remove_impute(data, target_impute, target_params = NULL, target_groups = NULL)
split any imputation from the intervals and remove it
warn if the imputation was not found in any of the intervals