diff --git a/.Rprofile b/.Rprofile index d059c2fcc5..6d46e67550 100644 --- a/.Rprofile +++ b/.Rprofile @@ -1,8 +1,7 @@ # Set renv profile base on R version. .get_dependencies <- function(project_dir) { - admdev_loc <- find.package("admiraldev", lib.loc = .libPaths(), quiet = TRUE) - adm_dev_suggests <- if(length(admdev_loc) != 0) { + adm_dev_suggests <- if (length(admdev_loc) != 0) { renv:::renv_dependencies_discover_description(admdev_loc, fields = c("Depends", "Imports", "LinkingTo", "Suggests")) } else { data.frame(Packages = character(0)) @@ -19,7 +18,7 @@ )) ) ) - packages[!(packages %in% c("admiral", "admiraldev", "admiralci", "admiral.test", "pharmaversesdtm", getwd()))] + packages[!(packages %in% c("admiral", "admiraldev", "admiralci", "pharmaversesdtm", getwd()))] } options(renv.snapshot.filter = .get_dependencies) diff --git a/.devcontainer/4.1/devcontainer.json b/.devcontainer/4.1/devcontainer.json index 1d05f7fdf1..ab6ddfeeae 100644 --- a/.devcontainer/4.1/devcontainer.json +++ b/.devcontainer/4.1/devcontainer.json @@ -31,7 +31,7 @@ "postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh", - "postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"", + "postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"; echo 'To open rstudio in your browser, just type rstudio in the terminal'", "customizations": { "vscode": { diff --git a/.devcontainer/4.2/devcontainer.json b/.devcontainer/4.2/devcontainer.json index f30486e0d8..decbcca545 100644 --- a/.devcontainer/4.2/devcontainer.json +++ b/.devcontainer/4.2/devcontainer.json @@ -31,7 +31,7 @@ "postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh", - "postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"", + "postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"; echo 'To open rstudio in your browser, just type rstudio in the terminal'", "customizations": { "vscode": { diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4f49db8fe5..3f47589f32 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -31,7 +31,7 @@ "postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh", - "postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"", + "postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"; echo 'To open rstudio in your browser, just type rstudio in the terminal'", "customizations": { "vscode": { diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh index 9b9db23af9..8dfe4e236e 100644 --- a/.devcontainer/postCreateCommand.sh +++ b/.devcontainer/postCreateCommand.sh @@ -1,5 +1,11 @@ #!/bin/bash +# move script rstudio into /usr/bin +sudo cp "$(pwd)/.devcontainer/rstudio.sh" /usr/bin/rstudio +sudo chmod +x /usr/bin/rstudio + +# Restore renv and install staged dependencies R -q -e 'renv::restore(lockfile = file.path("renv", "profiles", paste(R.version$major, substr(R.version$minor, 1, 1), sep = "."), "renv.lock")); staged.dependencies::install_deps(staged.dependencies::dependency_table(project = ".", verbose = 1), verbose = 1);' +# Define rstudio default working directory jq --arg folder "$(pwd)/" '. + { "initial_working_directory": $folder }' .devcontainer/rstudio-prefs.json > ~/.config/rstudio/rstudio-prefs.json diff --git a/.devcontainer/rstudio.sh b/.devcontainer/rstudio.sh new file mode 100644 index 0000000000..053a247b5b --- /dev/null +++ b/.devcontainer/rstudio.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +$BROWSER "https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" + +exit 1 diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 70de46c879..a0a47958ed 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -9,7 +9,7 @@ Please check off each taskbox as an acknowledgment that you completed the task o - [ ] Update to all relevant roxygen headers and examples, including keywords and families. Refer to the [categorization of functions](https://pharmaverse.github.io/admiraldev/devel/articles/programming_strategy.html#categorization-of-functions) to tag appropriate keyword/family. - [ ] Run `devtools::document()` so all `.Rd` files in the `man` folder and the `NAMESPACE` file in the project root are updated appropriately - [ ] Address any updates needed for vignettes and/or templates -- [ ] Update `NEWS.md` if the changes pertain to a user-facing function (i.e. it has an `@export` tag) or documentation aimed at users (rather than developers) +- [ ] Update `NEWS.md` under the header `# admiral (development version)` if the changes pertain to a user-facing function (i.e. it has an `@export` tag) or documentation aimed at users (rather than developers) - [ ] Build admiral site `pkgdown::build_site()` and check that all affected examples are displayed correctly and that all new functions occur on the "[Reference](https://pharmaverse.github.io/admiral/cran-release/reference/index.html)" page. - [ ] Address or fix all lintr warnings and errors - `lintr::lint_package()` - [ ] Run `R CMD check` locally and address all errors and warnings - `devtools::check()` diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index dc1fa875a9..01a35f6c13 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -15,17 +15,13 @@ on: - "v*" branches: - main - - devel - patch - - pre-release # 'pull_request' events are triggered when PRs are # created against one of these target branches. pull_request: branches: - main - - devel - patch - - pre-release # 'release' events are triggered when... # you guessed it - when releases are made. release: @@ -81,7 +77,7 @@ jobs: latest-tag-alt-name: cran-release multiversion-docs-landing-page: cran-release branches-or-tags-to-list: >- - ^cran-release$|^main$|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)$ + ^cran-release$|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)$ linter: name: Lint uses: pharmaverse/admiralci/.github/workflows/lintr.yml@main diff --git a/DESCRIPTION b/DESCRIPTION index e2f46de44e..02f6075009 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: admiral Type: Package Title: ADaM in R Asset Library -Version: 0.12.3 +Version: 0.12.2.9001 Authors@R: c( person("Ben", "Straub", email = "ben.x.straub@gsk.com", role = c("aut", "cre")), person("Stefan", "Bundfuss", role = "aut"), @@ -37,7 +37,7 @@ Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 -Depends: R (>= 3.5) +Depends: R (>= 4.0) Imports: admiraldev (>= 0.4.0), dplyr (>= 0.8.4), diff --git a/NAMESPACE b/NAMESPACE index e8b78072f6..9bf86be5c1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -69,7 +69,6 @@ export(derive_param_computed) export(derive_param_doseint) export(derive_param_exist_flag) export(derive_param_exposure) -export(derive_param_extreme_event) export(derive_param_extreme_record) export(derive_param_framingham) export(derive_param_map) @@ -84,19 +83,12 @@ export(derive_var_anrind) export(derive_var_atoxgr) export(derive_var_atoxgr_dir) export(derive_var_base) -export(derive_var_basetype) export(derive_var_chg) -export(derive_var_confirmation_flag) export(derive_var_dthcaus) export(derive_var_extreme_dt) export(derive_var_extreme_dtm) export(derive_var_extreme_flag) export(derive_var_joined_exist_flag) -export(derive_var_last_dose_amt) -export(derive_var_last_dose_date) -export(derive_var_last_dose_grp) -export(derive_var_merged_cat) -export(derive_var_merged_character) export(derive_var_merged_exist_flag) export(derive_var_merged_summary) export(derive_var_obs_number) @@ -115,7 +107,6 @@ export(derive_vars_dtm_to_tm) export(derive_vars_duration) export(derive_vars_dy) export(derive_vars_joined) -export(derive_vars_last_dose) export(derive_vars_merged) export(derive_vars_merged_lookup) export(derive_vars_period) diff --git a/NEWS.md b/NEWS.md index 63d4ea4a5b..1864b48ce0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,61 @@ +# admiral (development version) + +## New Features + +## Updates of Existing Functions + +- `derive_extreme_records()`, `derive_var_extreme_flag()`,`derive_vars_joined()` and `derive_vars_merged()` were enhanced with the arguments `true_value` and `false_value` to align with preexisting functions that had similar functionality (#2125) + +- `restrict_derivation()` now allows `{dplyr}` functions like `mutate` in the `derivation argument (#2143) + +- `derive_summary_records()`, `derive_var_merged_summary()`, and `get_summary_records()` +were enhanced such that more than one summary variable can be derived, e.g., +`AVAL` as the sum and `ADT` as the maximum of the contributing records. (#1792) + + +## Breaking Changes + +- In `derive_summary_records()` and `get_summary_records()` the arguments +`analysis_var` and `summary_fun` were deprecated in favor of `set_values_to`. +(#1792) + +- In `derive_var_merged_summary()` the arguments `new_var`, `analysis_var`, and +`summary_fun` were deprecated in favor of `new_vars`. (#1792) + +- admiral now only supports R >= 4.0.0 + +- For the function `derive_vars_merged()`, the argument `match_flag` was renamed to `exist_flag` (#2125) + +- The default value for the `false_value` argument in `derive_extreme_records()` was changed to `NA_character_` (#2125) + +- The following functions, which were deprecated in previous `{admiral}` versions, have been removed: (#2098) + - `derive_param_extreme_event()` + - `derive_vars_last_dose()` + - `derive_var_last_dose_amt()` + - `derive_var_last_dose_date()` + - `derive_var_last_dose_grp()` + - `derive_var_basetype()` + - `derive_var_merged_cat()` + - `derive_var_merged_character()` + - `derive_var_confirmation_flag()` + +- The following function arguments are entering the next phase of the deprecation process: (#2098) + + - `compute_egfr(wt)` + - `derive_extreme_records(filter)` + - `derive_param_computed(analysis_value, analysis_var)` + - `derive_var_shift(na_val)` + - `derive_expected_records(dataset_expected_obs)` + - `derive_var_ontrtfl(span_period)` + +## Documentation + +- A way to standardize roxygen labels and descriptions for function arguments was implemented and tested (#2034) + +- Link to published CDISC Population PK (ADPPK) implementation guide added. (#2161) + +## Various + # admiral 0.12.3 - Fixed a bug in `derive_var_dthcaus()` where if a subject has observations in diff --git a/R/call_derivation.R b/R/call_derivation.R index 6afa0c5b80..38ad64629c 100644 --- a/R/call_derivation.R +++ b/R/call_derivation.R @@ -3,7 +3,7 @@ #' Call a single derivation multiple times with some parameters/arguments being fixed across #' iterations and others varying. #' -#' @param dataset The input dataset +#' @param dataset `r roxygen_param_dataset()` #' @param derivation The derivation function to call #' #' A function that performs a specific derivation is expected. A derivation diff --git a/R/compute_kidney.R b/R/compute_kidney.R index 3d06062b56..7189b99179 100644 --- a/R/compute_kidney.R +++ b/R/compute_kidney.R @@ -137,9 +137,7 @@ compute_egfr <- function(creat, creatu = "SI", age, weight, sex, race = NULL, method, wt) { ### BEGIN DEPRECATION if (!missing(wt)) { - deprecate_warn("0.12.0", "compute_egfr(old_param = 'wt')", "compute_egfr(new_param = 'weight')") - # old_param is given using exprs() - weight <- wt + deprecate_stop("0.12.0", "compute_egfr(old_param = 'wt')", "compute_egfr(new_param = 'weight')") } ### END DEPRECATION diff --git a/R/create_single_dose_dataset.R b/R/create_single_dose_dataset.R index 1a0c782b24..936593cea0 100644 --- a/R/create_single_dose_dataset.R +++ b/R/create_single_dose_dataset.R @@ -185,10 +185,8 @@ dose_freq_lookup <- tribble( #' necessary when e.g. calculating last dose before an adverse event in `ADAE` #' or deriving a total dose parameter in `ADEX` when `EXDOSFRQ != ONCE`. #' -#' @param dataset Input dataset -#' -#' The columns specified by `dose_freq`, `start_date` and the `end_date` -#' parameters are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("dose_freq", "start_date", "end_date"))` #' #' @param dose_freq The dose frequency #' diff --git a/R/derive_adeg_params.R b/R/derive_adeg_params.R index 05ae271421..5c8afc3a80 100644 --- a/R/derive_adeg_params.R +++ b/R/derive_adeg_params.R @@ -6,10 +6,9 @@ #' #' **Note:** This is a wrapper function for the more generic `derive_param_computed()`. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` and the `unit_var` parameter, -#' `PARAMCD`, and `AVAL` are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars", "get_unit_expr"))` +#' `PARAMCD`, and `AVAL` are expected as well. #' #' The variable specified by `by_vars` and `PARAMCD` must be a unique key of #' the input dataset after restricting it by the filter condition (`filter` @@ -257,10 +256,9 @@ compute_qtc <- function(qt, rr, method) { #' The analysis value of the new parameter is derived as #' \deqn{\frac{60000}{HR}}{60000 / HR} #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` parameter, `PARAMCD`, and `AVAL` -#' are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` +#' `PARAMCD`, and `AVAL` are expected as well. #' #' The variable specified by `by_vars` and `PARAMCD` must be a unique key of #' the input dataset after restricting it by the filter condition (`filter` diff --git a/R/derive_advs_params.R b/R/derive_advs_params.R index 881db1b92f..06e646a90a 100644 --- a/R/derive_advs_params.R +++ b/R/derive_advs_params.R @@ -5,10 +5,9 @@ #' #' **Note:** This is a wrapper function for the more generic `derive_param_computed()`. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` parameter, `PARAMCD`, and -#' `AVAL` are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` +#' `PARAMCD`, and `AVAL` are expected as well. #' #' The variable specified by `by_vars` and `PARAMCD` must be a unique key of #' the input dataset after restricting it by the filter condition (`filter` @@ -226,10 +225,9 @@ compute_map <- function(diabp, sysbp, hr = NULL) { #' #' **Note:** This is a wrapper function for the more generic `derive_param_computed()`. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` parameter, `PARAMCD`, and -#' `AVAL` are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` +#' `PARAMCD`, and `AVAL` are expected as well. #' #' The variable specified by `by_vars` and `PARAMCD` must be a unique key of #' the input dataset after restricting it by the filter condition (`filter` @@ -549,10 +547,9 @@ compute_bsa <- function(height = height, #' #' **Note:** This is a wrapper function for the more generic `derive_param_computed()`. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` parameter, `PARAMCD`, and -#' `AVAL` are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` +#' `PARAMCD`, and `AVAL` are expected as well. #' #' The variable specified by `by_vars` and `PARAMCD` must be a unique key of #' the input dataset after restricting it by the filter condition (`filter` diff --git a/R/derive_basetype_records.R b/R/derive_basetype_records.R index ef81d4cab4..c1b4cf85b9 100644 --- a/R/derive_basetype_records.R +++ b/R/derive_basetype_records.R @@ -12,9 +12,8 @@ #' Adds the `BASETYPE` variable to a dataset and duplicates records based upon #' the provided conditions. #' -#' @param dataset Input dataset -#' -#' The columns specified in the expressions inside `basetypes` are required. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("basetypes"))` #' #' @param basetypes A *named* list of expressions created using the #' `rlang::exprs()` function diff --git a/R/derive_date_vars.R b/R/derive_date_vars.R index 3bafc333cb..183e094227 100644 --- a/R/derive_date_vars.R +++ b/R/derive_date_vars.R @@ -1252,9 +1252,8 @@ compute_tmf <- function(dtc, #' impute, we only enable to impute up to a highest level, i.e. you couldn't #' choose to say impute months, but not days. #' -#' @param dataset Input dataset. -#' -#' The date character vector (`dtc`) must be present. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("dtc"))` #' #' @param new_vars_prefix Prefix used for the output variable(s). #' @@ -1461,9 +1460,8 @@ derive_vars_dt <- function(dataset, # nolint: cyclocomp_linter #' impute, we only enable to impute up to a highest level, i.e. you couldn't #' choose to say impute months, but not days. #' -#' @param dataset Input dataset -#' -#' The date character vector (`dtc`) must be present. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("dtc"))` #' #' @param new_vars_prefix Prefix used for the output variable(s). #' diff --git a/R/derive_expected_records.R b/R/derive_expected_records.R index f61cf2dab9..1369267729 100644 --- a/R/derive_expected_records.R +++ b/R/derive_expected_records.R @@ -3,10 +3,8 @@ #' Add expected records as new observations for each 'by group' when the dataset #' contains missing observations. #' -#' @param dataset Input dataset -#' -#' A data frame, the columns from `dataset_ref` and specified by the -#' `by_vars` parameter are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("dataset_ref", "by_vars"))` #' #' @param dataset_expected_obs *Deprecated*, please use `dataset_ref` instead. #' @@ -91,7 +89,7 @@ derive_expected_records <- function(dataset, by_vars = NULL, set_values_to = NULL) { if (!missing(dataset_expected_obs)) { - deprecate_warn( + deprecate_stop( "0.12.0", "derive_expected_records(dataset_expected_obs = )", "derive_expected_records(dataset_ref = )" diff --git a/R/derive_extreme_records.R b/R/derive_extreme_records.R index 4093aab5bd..f63698d17e 100644 --- a/R/derive_extreme_records.R +++ b/R/derive_extreme_records.R @@ -7,7 +7,7 @@ #' distinguishes `derive_extreme_records()` from `derive_summary_records()`, #' where only the by variables are populated for the new records. #' -#' @param dataset Input dataset +#' @param dataset `r roxygen_param_dataset()` #' #' If `dataset_add` is not specified, the new records are selected from the #' input dataset. In this case the variables specified by `by_vars` and @@ -84,16 +84,13 @@ #' For new observations not selected from the additional dataset #' (`dataset_add`), `exist_flag` is set to the specified value. #' +#' @param keep_source_vars Variables to be kept in the new records #' -#' @param filter Filter for observations to consider -#' -#' *Deprecated*, please use the above `filter_add` argument instead. -#' -#' Only observations fulfilling the specified condition are taken into account -#' for selecting the first or last observation. If the argument is not -#' specified, all observations are considered. +#' A named list or tidyselect expressions created by `exprs()` defining the +#' variables to be kept for the new records. The variables specified for +#' `by_vars` and `set_values_to` need not be specified here as they are kept +#' automatically. #' -#' *Permitted Values*: a condition #' #' @param keep_source_vars Variables to be kept in the new records #' @@ -266,19 +263,9 @@ derive_extreme_records <- function(dataset = NULL, check_type = "warning", exist_flag = NULL, true_value = "Y", - false_value = "N", + false_value = NA_character_, keep_source_vars = exprs(everything()), - set_values_to, - filter) { - if (!missing(filter)) { - deprecate_stop( - "0.11.0", - "derive_extreme_records(filter = )", - "derive_extreme_records(filter_add = )" - ) - filter_add <- enexpr(filter) - } - + set_values_to) { # Check input arguments assert_vars(by_vars, optional = is.null(dataset_ref)) assert_expr_list(order, optional = TRUE) diff --git a/R/derive_joined.R b/R/derive_joined.R index 1e0f5cff48..f166e05031 100644 --- a/R/derive_joined.R +++ b/R/derive_joined.R @@ -6,9 +6,8 @@ #' variables from both datasets. For example, add the lowest value (nadir) #' before the current observation. #' -#' @param dataset Input dataset -#' -#' The variables specified by `by_vars` are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` #' #' @param dataset_add Additional dataset #' @@ -330,6 +329,9 @@ derive_vars_joined <- function(dataset, filter_add = NULL, filter_join = NULL, mode = NULL, + exist_flag = NULL, + true_value = "Y", + false_value = NA_character_, missing_values = NULL, check_type = "warning") { assert_vars(by_vars, optional = TRUE) @@ -424,6 +426,9 @@ derive_vars_joined <- function(dataset, new_vars = add_suffix_to_vars(new_vars, vars = common_vars, suffix = ".join"), missing_values = missing_values, check_type = check_type, + exist_flag = !!enexpr(exist_flag), + true_value = true_value, + false_value = false_value, duplicate_msg = paste( paste( "After applying `filter_join` the joined dataset contains more", diff --git a/R/derive_locf_records.R b/R/derive_locf_records.R index ad13927788..55339fb16c 100644 --- a/R/derive_locf_records.R +++ b/R/derive_locf_records.R @@ -3,10 +3,8 @@ #' Adds LOCF records as new observations for each 'by group' when the dataset #' does not contain observations for missed visits/time points. #' -#' @param dataset Input dataset -#' -#' The columns specified by the `by_vars`, `analysis_var`, `order`, -#' `keep_vars` parameters are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars", "analysis_var", "order", "keep_vars"))` #' #' @param dataset_expected_obs *Deprecated*, please use `dataset_ref` instead. #' @@ -119,7 +117,7 @@ derive_locf_records <- function(dataset, order, keep_vars = NULL) { if (!missing(dataset_expected_obs)) { - deprecate_warn( + deprecate_stop( "0.12.0", "derive_locf_records(dataset_expected_obs = )", "derive_locf_records(dataset_ref = )" diff --git a/R/derive_merged.R b/R/derive_merged.R index 428209efaa..0bd7e9b279 100644 --- a/R/derive_merged.R +++ b/R/derive_merged.R @@ -6,9 +6,8 @@ #' (`filter_add` argument) and/or selecting the first or last observation for #' each by group (`order` and `mode` argument). #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` argument are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` #' #' @param dataset_add Additional dataset #' @@ -82,6 +81,8 @@ #' #' @param match_flag Match flag #' +#' `r lifecycle::badge("deprecated")` Please use `exist_flag` instead. +#' #' If the argument is specified (e.g., `match_flag = FLAG`), the specified #' variable (e.g., `FLAG`) is added to the input dataset. This variable will #' be `TRUE` for all selected records from `dataset_add` which are merged into @@ -89,6 +90,29 @@ #' #' *Permitted Values*: Variable name #' +#' @param exist_flag Exist flag +#' +#' If the argument is specified (e.g., `exist_flag = FLAG`), the specified +#' variable (e.g., `FLAG`) is added to the input dataset. This variable will +#' be the value provided in `true_value` for all selected records from `dataset_add` +#' which are merged into the input dataset, and the value provided in `false_value` otherwise. +#' +#' *Permitted Values*: Variable name +#' +#' @param true_value True value +#' +#' The value for the specified variable `exist_flag`, applicable to +#' the first or last observation (depending on the mode) of each by group. +#' +#' Permitted Values: An atomic scalar +#' +#' @param false_value False value +#' +#' The value for the specified variable `exist_flag`, NOT applicable to +#' the first or last observation (depending on the mode) of each by group. +#' +#' Permitted Values: An atomic scalar +#' #' @param missing_values Values for non-matching observations #' #' For observations of the input dataset (`dataset`) which do not have a @@ -199,7 +223,7 @@ #' mode = "last", #' new_vars = exprs(LASTWGT = VSSTRESN, LASTWGTU = VSSTRESU), #' filter_add = VSTESTCD == "WEIGHT", -#' match_flag = vsdatafl +#' exist_flag = vsdatafl #' ) %>% #' select(STUDYID, USUBJID, AGE, AGEU, LASTWGT, LASTWGTU, vsdatafl) #' @@ -283,7 +307,10 @@ derive_vars_merged <- function(dataset, new_vars = NULL, filter_add = NULL, mode = NULL, - match_flag = NULL, + match_flag, + exist_flag = NULL, + true_value = "Y", + false_value = NA_character_, missing_values = NULL, check_type = "warning", duplicate_msg = NULL) { @@ -302,7 +329,17 @@ derive_vars_merged <- function(dataset, extract_vars(new_vars) ) ) - match_flag <- assert_symbol(enexpr(match_flag), optional = TRUE) + if (!is_missing(enexpr(match_flag))) { + deprecate_warn( + "1.0.0", + "derive_vars_merged(match_flag =)", + "derive_vars_merged(exist_flag =)" + ) + exist_flag <- assert_symbol(enexpr(match_flag), optional = TRUE) + } + exist_flag <- assert_symbol(enexpr(exist_flag), optional = TRUE) + assert_atomic_vector(true_value, optional = TRUE) + assert_atomic_vector(false_value, optional = TRUE) assert_expr_list(missing_values, named = TRUE, optional = TRUE) if (!is.null(missing_values)) { invalid_vars <- setdiff( @@ -348,18 +385,18 @@ derive_vars_merged <- function(dataset, select(!!!by_vars_right, !!!replace_values_by_names(new_vars)) } - if (!is.null(missing_values)) { + if (!is.null(missing_values) || !is.null(exist_flag)) { match_flag_var <- get_new_tmp_var(add_data, prefix = "tmp_match_flag") } else { - match_flag_var <- match_flag + match_flag_var <- NULL } - if (!is.null(match_flag_var)) { add_data <- mutate( add_data, !!match_flag_var := TRUE ) } + # check if there are any variables in both datasets which are not by vars # in this case an error is issued to avoid renaming of varibles by left_join() common_vars <- @@ -383,7 +420,7 @@ derive_vars_merged <- function(dataset, } dataset <- left_join(dataset, add_data, by = vars2chr(by_vars)) - if (!is.null(missing_values)) { + if (!is.null(match_flag_var)) { update_missings <- map2( syms(names(missing_values)), missing_values, @@ -391,82 +428,16 @@ derive_vars_merged <- function(dataset, ) names(update_missings) <- names(missing_values) dataset <- dataset %>% - mutate(!!!update_missings) %>% - remove_tmp_vars() + mutate(!!!update_missings) } - dataset -} -#' Merge a Categorization Variable -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `derive_vars_merged()` instead. -#' -#' Merge a categorization variable from a dataset to the input dataset. The -#' observations to merge can be selected by a condition and/or selecting the -#' first or last observation for each by group. -#' -#' @param dataset_add Additional dataset -#' -#' The variables specified by the `by_vars`, the `source_var`, and the `order` -#' argument are expected. -#' -#' @param new_var New variable -#' -#' The specified variable is added to the additional dataset and set to the -#' categorized values, i.e., `cat_fun()`. -#' -#' @param source_var Source variable -#' -#' @param cat_fun Categorization function -#' -#' A function must be specified for this argument which expects the values of -#' the source variable as input and returns the categorized values. -#' -#' @param missing_value Values used for missing information -#' -#' The new variable is set to the specified value for all by groups without -#' observations in the additional dataset. -#' -#' *Default*: `NA_character_` -#' -#' @inheritParams derive_vars_merged -#' -#' @return The output dataset contains all observations and variables of the -#' input dataset and additionally the variable specified for `new_var` derived -#' from the additional dataset (`dataset_add`). -#' -#' @details -#' -#' 1. The additional dataset is restricted to the observations matching the -#' `filter_add` condition. -#' -#' 1. The categorization variable is added to the additional dataset. -#' -#' 1. If `order` is specified, for each by group the first or last observation -#' (depending on `mode`) is selected. -#' -#' 1. The categorization variable is merged to the input dataset. -#' -#' -#' @family deprecated -#' @keywords deprecated -#' -#' @export -#' -derive_var_merged_cat <- function(dataset, - dataset_add, - by_vars, - order = NULL, - new_var, - source_var, - cat_fun, - filter_add = NULL, - mode = NULL, - missing_value = NA_character_) { - deprecate_stop("0.11.0", "derive_var_merged_cat()", "derive_vars_merged()") + if (!is.null(exist_flag)) { + dataset <- dataset %>% + mutate(!!exist_flag := ifelse(is.na(!!match_flag_var), false_value, true_value)) + } + + dataset %>% + remove_tmp_vars() } #' Merge an Existence Flag @@ -633,83 +604,6 @@ derive_var_merged_exist_flag <- function(dataset, mutate(!!new_var := if_else(!!new_var == 1, true_value, false_value, missing_value)) } -#' Merge a Character Variable -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `derive_vars_merged()` instead. -#' -#' Merge a character variable from a dataset to the input dataset. The -#' observations to merge can be selected by a condition and/or selecting the -#' first or last observation for each by group. -#' -#' @param dataset_add Additional dataset -#' -#' The variables specified by the `by_vars`, the `source_var`, and the `order` -#' argument are expected. -#' -#' @param new_var New variable -#' -#' The specified variable is added to the additional dataset and set to the -#' transformed value with respect to the `case` argument. -#' -#' @param source_var Source variable -#' -#' @param case Change case -#' -#' Changes the case of the values of the new variable. -#' -#' *Default*: `NULL` -#' -#' *Permitted Values*: `NULL`, `"lower"`, `"upper"`, `"title"` -#' -#' @param missing_value Values used for missing information -#' -#' The new variable is set to the specified value for all by groups without -#' observations in the additional dataset. -#' -#' *Default*: `NA_character_` -#' -#' *Permitted Value*: A character scalar -#' -#' @inheritParams derive_vars_merged -#' -#' @return The output dataset contains all observations and variables of the -#' input dataset and additionally the variable specified for `new_var` derived -#' from the additional dataset (`dataset_add`). -#' -#' @details -#' -#' 1. The additional dataset is restricted to the observations matching the -#' `filter_add` condition. -#' -#' 1. The (transformed) character variable is added to the additional dataset. -#' -#' 1. If `order` is specified, for each by group the first or last observation -#' (depending on `mode`) is selected. -#' -#' 1. The character variable is merged to the input dataset. -#' -#' -#' @family deprecated -#' @keywords deprecated -#' -#' @export -derive_var_merged_character <- function(dataset, - dataset_add, - by_vars, - order = NULL, - new_var, - source_var, - case = NULL, - filter_add = NULL, - mode = NULL, - missing_value = NA_character_) { - deprecate_stop("0.11.0", "derive_var_merged_character()", "derive_vars_merged()") -} - - #' Merge Lookup Table with Source Dataset #' #' Merge user-defined lookup table with the input dataset. Optionally print a @@ -801,6 +695,8 @@ derive_vars_merged_lookup <- function(dataset, assert_logical_scalar(print_not_mapped) filter_add <- assert_filter_cond(enexpr(filter_add), optional = TRUE) + tmp_lookup_flag <- get_new_tmp_var(dataset_add, prefix = "tmp_lookup_flag") + res <- derive_vars_merged( dataset, dataset_add, @@ -809,14 +705,14 @@ derive_vars_merged_lookup <- function(dataset, new_vars = new_vars, mode = mode, filter_add = !!filter_add, - match_flag = temp_match_flag, + exist_flag = !!tmp_lookup_flag, check_type = check_type, duplicate_msg = duplicate_msg ) if (print_not_mapped) { temp_not_mapped <- res %>% - filter(is.na(temp_match_flag)) %>% + filter(is.na(!!tmp_lookup_flag)) %>% distinct(!!!by_vars_left) if (nrow(temp_not_mapped) > 0) { @@ -838,7 +734,7 @@ derive_vars_merged_lookup <- function(dataset, } } - res %>% select(-temp_match_flag) + res %>% remove_tmp_vars() } #' Get list of records not mapped from the lookup table. @@ -853,34 +749,51 @@ get_not_mapped <- function() { admiral_environment$nmap } -#' Merge a Summary Variable +#' Merge Summary Variables #' #' @description Merge a summary variable from a dataset to the input dataset. #' -#' **Note:** This is a wrapper function for the more generic `derive_vars_merged`. -#' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` argument are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` #' #' @param dataset_add Additional dataset #' -#' The variables specified by the `by_vars` and the `analysis_var` arguments -#' are expected. +#' The variables specified by the `by_vars` and the variables used on the left +#' hand sides of the `new_vars` arguments are expected. #' #' @param new_var Variable to add #' +#' `r lifecycle::badge("deprecated")` Please use `new_vars` instead. +#' #' The specified variable is added to the input dataset (`dataset`) and set to #' the summarized values. #' #' @param by_vars Grouping variables #' -#' The values of `analysis_var` are summarized by the specified variables. The -#' summarized values are merged to the input dataset (`dataset`) by the -#' specified by variables. +#' The expressions on the left hand sides of `new_vars` are evaluated by the +#' specified *variables*. Then the resulting values are merged to the input +#' dataset (`dataset`) by the specified *variables*. #' #' *Permitted Values*: list of variables created by `exprs()` #' +#' @param new_vars New variables to add +#' +#' The specified variables are added to the input dataset. +#' +#' A named list of expressions is expected: +#' + LHS refer to a variable. +#' + RHS refers to the values to set to the variable. This can be a string, a +#' symbol, a numeric value, an expression or NA. If summary functions are +#' used, the values are summarized by the variables specified for `by_vars`. +#' +#' For example: +#' ``` +#' new_vars = exprs( +#' DOSESUM = sum(AVAL), +#' DOSEMEAN = mean(AVAL) +#' ) +#' ``` +#' #' @param filter_add Filter for additional dataset (`dataset_add`) #' #' Only observations fulfilling the specified condition are taken into account @@ -891,11 +804,15 @@ get_not_mapped <- function() { #' #' @param analysis_var Analysis variable #' +#' `r lifecycle::badge("deprecated")` Please use `new_vars` instead. +#' #' The values of the specified variable are summarized by the function #' specified for `summary_fun`. #' #' @param summary_fun Summary function #' +#' `r lifecycle::badge("deprecated")` Please use `new_vars` instead. +#' #' The specified function that takes as input `analysis_var` and performs the #' calculation. This can include built-in functions as well as user defined #' functions, for example `mean` or `function(x) mean(x, na.rm = TRUE)`. @@ -906,18 +823,17 @@ get_not_mapped <- function() { #' 1. The records from the additional dataset (`dataset_add`) are restricted #' to those matching the `filter_add` condition. #' -#' 1. The values of the analysis variable (`analysis_var`) are summarized by -#' the summary function (`summary_fun`) for each by group (`by_vars`) in the -#' additional dataset (`dataset_add`). +#' 1. The new variables (`new_vars`) are created for each by group (`by_vars`) +#' in the additional dataset (`dataset_add`) by calling `summarize()`. I.e., +#' all observations of a by group are summarized to a single observation. #' -#' 1. The summarized values are merged to the input dataset as a new variable -#' (`new_var`). For observations without a matching observation in the -#' additional dataset the new variable is set to `NA`. Observations in the -#' additional dataset which have no matching observation in the input dataset -#' are ignored. +#' 1. The new variables are merged to the input dataset. For observations +#' without a matching observation in the additional dataset the new variables +#' are set to `NA`. Observations in the additional dataset which have no +#' matching observation in the input dataset are ignored. #' #' @return The output dataset contains all observations and variables of the -#' input dataset and additionally the variable specified for `new_var`. +#' input dataset and additionally the variables specified for `new_vars`. #' #' @family der_gen #' @keywords der_gen @@ -947,9 +863,10 @@ get_not_mapped <- function() { #' adbds, #' dataset_add = adbds, #' by_vars = exprs(USUBJID, AVISIT), -#' new_var = MEANVIS, -#' analysis_var = AVAL, -#' summary_fun = function(x) mean(x, na.rm = TRUE) +#' new_vars = exprs( +#' MEANVIS = mean(AVAL, na.rm = TRUE), +#' MAXVIS = max(AVAL, na.rm = TRUE) +#' ) #' ) #' #' # Add a variable listing the lesion ids at baseline @@ -981,14 +898,13 @@ get_not_mapped <- function() { #' dataset_add = adtr, #' by_vars = exprs(USUBJID), #' filter_add = AVISIT == "BASELINE", -#' new_var = LESIONSBL, -#' analysis_var = LESIONID, -#' summary_fun = function(x) paste(x, collapse = ", ") +#' new_vars = exprs(LESIONSBL = paste(LESIONID, collapse = ", ")) #' ) #' derive_var_merged_summary <- function(dataset, dataset_add, by_vars, + new_vars = NULL, new_var, filter_add = NULL, analysis_var, @@ -996,20 +912,31 @@ derive_var_merged_summary <- function(dataset, assert_vars(by_vars) by_vars_left <- replace_values_by_names(by_vars) by_vars_right <- chr2vars(paste(vars2chr(by_vars))) - new_var <- assert_symbol(enexpr(new_var)) - analysis_var <- assert_symbol(enexpr(analysis_var)) + # once new_var is removed new_vars should be mandatory + assert_expr_list(new_vars, named = TRUE, optional = TRUE) filter_add <- assert_filter_cond(enexpr(filter_add), optional = TRUE) - assert_s3_class(summary_fun, "function") assert_data_frame( dataset, required_vars = by_vars_left ) assert_data_frame( dataset_add, - required_vars = expr_c(by_vars_right, analysis_var) + required_vars = expr_c(by_vars_right, extract_vars(new_vars)) ) + if (!missing(new_var) || !missing(analysis_var) || !missing(summary_fun)) { + deprecate_warn( + "1.0.0", + I("derive_var_merged_summary(new_var = , anaylsis_var = , summary_fun = )"), + "derive_var_merged_summary(new_vars = )" + ) + new_var <- assert_symbol(enexpr(new_var)) + analysis_var <- assert_symbol(enexpr(analysis_var)) + assert_s3_class(summary_fun, "function") + new_vars <- exprs(!!new_var := {{ summary_fun }}(!!analysis_var), !!!new_vars) + } + # Summarise the analysis value and merge to the original dataset derive_vars_merged( dataset, @@ -1017,10 +944,9 @@ derive_var_merged_summary <- function(dataset, dataset_add, by_vars = by_vars_right, filter = !!filter_add, - analysis_var = !!analysis_var, - summary_fun = summary_fun - ), - by_vars = by_vars, - new_vars = exprs(!!new_var := !!analysis_var) + set_values_to = new_vars, + ) %>% + select(!!!by_vars_right, names(new_vars)), + by_vars = by_vars ) } diff --git a/R/derive_param_computed.R b/R/derive_param_computed.R index ac5b43314c..4a9f1b1600 100644 --- a/R/derive_param_computed.R +++ b/R/derive_param_computed.R @@ -7,9 +7,9 @@ #' blood pressure (DIABP) with the formula #' \deqn{MAP = \frac{SYSBP + 2 DIABP}{3}}{MAP = (SYSBP + 2 DIABP) / 3} #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` parameter are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` +#' `PARAMCD` is expected as well. #' #' The variable specified by `by_vars` and `PARAMCD` must be a unique key of #' the input dataset after restricting it by the filter condition (`filter` @@ -304,7 +304,7 @@ derive_param_computed <- function(dataset = NULL, assert_logical_scalar(keep_nas) ### BEGIN DEPRECATION if (!missing(analysis_var)) { - deprecate_warn( + deprecate_stop( "0.12.0", "derive_param_computed(analysis_var = )", "derive_param_computed(set_values_to = )" @@ -313,7 +313,7 @@ derive_param_computed <- function(dataset = NULL, analysis_var <- assert_symbol(enexpr(analysis_var)) if (!missing(analysis_value)) { - deprecate_warn( + deprecate_stop( "0.12.0", "derive_param_computed(analysis_value = )", "derive_param_computed(set_values_to = )" @@ -428,7 +428,8 @@ assert_parameters_argument <- function(parameters, optional = TRUE) { #' The function creates temporary parameters and variables of the form #' `.`, e.g., `AVAL.WEIGHT`. #' -#' @param dataset Input dataset +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` #' #' @param by_vars By variables #' diff --git a/R/derive_param_doseint.R b/R/derive_param_doseint.R index 016af0088b..6a863e8891 100644 --- a/R/derive_param_doseint.R +++ b/R/derive_param_doseint.R @@ -8,10 +8,9 @@ #' The analysis value of the new parameter is derived as #' Total Dose / Planned Dose * 100 #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` parameter, `PARAMCD`, and -#' `AVAL` are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` +#' `PARAMCD`, and `AVAL` are expected as well. #' #' The variable specified by `by_vars` and `PARAMCD` must be a unique key of #' the input dataset after restricting it by the filter condition (`filter` diff --git a/R/derive_param_exist_flag.R b/R/derive_param_exist_flag.R index cd5a044202..6ecad23db6 100644 --- a/R/derive_param_exist_flag.R +++ b/R/derive_param_exist_flag.R @@ -5,10 +5,9 @@ #' function can derive a parameter indicating if there is measurable disease at #' baseline. #' -#' @param dataset Input dataset -#' -#' The variables specified for `by_vars` and the `PARAMCD` variable are -#' expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` +#' `PARAMCD` is expected as well. #' #' @param dataset_ref Reference dataset, e.g., ADSL #' @@ -75,11 +74,6 @@ #' #' *Permitted Values*: a condition #' -#' @param aval_fun Function to map character analysis value (`AVALC`) to numeric -#' analysis value (`AVAL`) -#' -#' *Deprecated*, please use `set_values_to` instead. -#' #' @param set_values_to Variables to set #' #' A named list returned by `exprs()` defining the variables to be set for the @@ -91,10 +85,6 @@ #' #' A list of symbols created using `exprs()` is expected. #' -#' @param dataset_adsl *Deprecated*, please use `dataset_ref` instead. -#' -#' @param subject_keys *Deprecated*, please use `by_vars` instead. -#' #' @details #' 1. The additional dataset (`dataset_add`) is restricted to the observations #' matching the `filter_add` condition. @@ -177,27 +167,8 @@ derive_param_exist_flag <- function(dataset = NULL, false_value = NA_character_, missing_value = NA_character_, filter_add = NULL, - aval_fun, by_vars = get_admiral_option("subject_keys"), - set_values_to, - dataset_adsl, - subject_keys) { - ### BEGIN DEPRECATION - if (!missing(dataset_adsl)) { - deprecate_stop( - "0.11.0", "derive_param_exist_flag(dataset_adsl = )", - "derive_param_exit_flag(dataset_ref = )" - ) - } - - if (!missing(subject_keys)) { - deprecate_stop( - "0.11.0", "derive_param_exist_flag(subject_keys = )", - "derive_param_exit_flag(by_vars = )" - ) - } - ### END DEPRECATION - + set_values_to) { # Check input parameters condition <- assert_filter_cond(enexpr(condition)) assert_character_scalar(true_value) @@ -217,15 +188,6 @@ derive_param_exist_flag <- function(dataset = NULL, assert_param_does_not_exist(dataset, set_values_to$PARAMCD) } - if (!missing(aval_fun)) { - assert_function(aval_fun) - deprecate_stop( - "0.11.0", - "derive_param_exist_flag(aval_fun = )", - "derive_param_exist_flag(set_values_to = )" - ) - } - # Create new observations new_obs <- derive_var_merged_exist_flag( dataset_ref, diff --git a/R/derive_param_exposure.R b/R/derive_param_exposure.R index 652e9d2992..3c0e81c6b3 100644 --- a/R/derive_param_exposure.R +++ b/R/derive_param_exposure.R @@ -3,10 +3,9 @@ #' Add a record computed from the aggregated analysis value of another parameter and compute the #' start (`ASTDT(M)`)and end date (`AENDT(M)`) as the minimum and maximum date by `by_vars`. #' -#' @param dataset Input dataset -#' -#' + The variables specified by the `by_vars`,`analysis_var` parameters and `PARAMCD` are -#' expected, +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars", "analysis_var"))` +#' `PARAMCD` is expected as well, #' + Either `ASTDTM` and `AENDTM` or `ASTDT` and `AENDT` are also expected. #' #' @param filter Filter condition @@ -138,11 +137,23 @@ derive_param_exposure <- function(dataset, dtm <- c("ASTDTM", "AENDTM") %in% colnames(dataset) dt <- c("ASTDT", "AENDT") %in% colnames(dataset) + set_dtm <- NULL + set_dt <- NULL if (all(dtm)) { dates <- exprs(ASTDTM, AENDTM) + set_dtm <- exprs( + ASTDTM = min(ASTDTM, na.rm = TRUE), + AENDTM = max(coalesce(AENDTM, ASTDTM), na.rm = TRUE) + ) } else { dates <- exprs(ASTDT, AENDT) } + if (all(dt)) { + set_dt <- exprs( + ASTDT = min(ASTDT, na.rm = TRUE), + AENDT = max(coalesce(AENDT, ASTDT), na.rm = TRUE) + ) + } assert_data_frame(dataset, required_vars = expr_c(by_vars, analysis_var, exprs(PARAMCD), dates) @@ -155,57 +166,19 @@ derive_param_exposure <- function(dataset, assert_character_vector(input_code, values = params_available) assert_s3_class(summary_fun, "function") - subset_ds <- dataset %>% - filter_if(filter) - - add_data <- subset_ds %>% - get_summary_records( - by_vars = by_vars, - filter = PARAMCD == !!input_code, - analysis_var = !!analysis_var, - summary_fun = summary_fun, - set_values_to = set_values_to - ) - - # add the dates for the derived parameters - tmp_start <- get_new_tmp_var(dataset) - tmp_end <- get_new_tmp_var(dataset) - if (all(dtm)) { - dates <- subset_ds %>% - group_by(!!!by_vars) %>% - summarise( - !!tmp_start := min(ASTDTM, na.rm = TRUE), - !!tmp_end := max(coalesce(AENDTM, ASTDTM), na.rm = TRUE) - ) %>% - ungroup() - expo_data <- add_data %>% - derive_vars_merged(dataset_add = dates, by_vars = by_vars) %>% - mutate( - ASTDTM = !!tmp_start, - AENDTM = !!tmp_end - ) %>% - remove_tmp_vars() - - if (all(dt)) { - expo_data <- expo_data %>% - mutate(ASTDT = date(ASTDTM), AENDT = date(AENDTM)) - } - } else { - dates <- subset_ds %>% - group_by(!!!by_vars) %>% - summarise( - !!tmp_start := min(ASTDT, na.rm = TRUE), - !!tmp_end := max(coalesce(AENDT, ASTDT), na.rm = TRUE) - ) %>% - ungroup() - expo_data <- add_data %>% - derive_vars_merged(dataset_add = dates, by_vars = by_vars) %>% - mutate( - ASTDT = !!tmp_start, - AENDT = !!tmp_end - ) %>% - remove_tmp_vars() + if (is.null(filter)) { + filter <- TRUE } - bind_rows(dataset, expo_data) + derive_summary_records( + dataset, + by_vars = by_vars, + filter = PARAMCD == !!input_code & !!filter, + set_values_to = exprs( + !!analysis_var := {{ summary_fun }}(!!analysis_var), + !!!set_dtm, + !!!set_dt, + !!!set_values_to + ) + ) } diff --git a/R/derive_param_extreme_event.R b/R/derive_param_extreme_event.R deleted file mode 100644 index 0b3048e61c..0000000000 --- a/R/derive_param_extreme_event.R +++ /dev/null @@ -1,128 +0,0 @@ -#' Add an Extreme Event Parameter -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `derive_extreme_records()` instead. -#' -#' Add a new parameter for the first or last event occurring in a dataset. The -#' variable given in `new_var` indicates if an event occurred or not. For -#' example, the function can derive a parameter for the first disease -#' progression. -#' -#' @param dataset Input dataset -#' -#' The `PARAMCD` variable is expected. -#' -#' @param dataset_adsl ADSL input dataset -#' -#' The variables specified for `subject_keys` are expected. For each -#' observation of the specified dataset a new observation is added to the -#' input dataset. -#' -#' @param dataset_source Source dataset -#' -#' All observations in the specified dataset fulfilling the condition -#' specified by `filter_source` are considered as an event. -#' -#' The variables specified by the `subject_keys` and -#' `order` argument (if applicable) are expected. -#' -#' @param filter_source Source filter -#' -#' All observations in `dataset_source` fulfilling the specified condition are -#' considered as an event. -#' -#' For subjects with at least one event `new_var` is set to `true_value`. -#' -#' For all other subjects `new_var` is set to `false_value`. -#' -#' @param order Order variable -#' -#' List of symbols for sorting the source dataset (`dataset_source`). -#' -#' *Permitted Values*: list of expressions created by `exprs()`, e.g., -#' `exprs(ADT, desc(AVAL))`. -#' -#' @param new_var New variable -#' -#' The name of the variable which will indicate whether an event happened or not. -#' -#' @param true_value True value -#' -#' For all subjects with at least one observation in the source dataset -#' (`dataset_source`) fulfilling the event condition (`filter_source`), -#' `new_var` is set to the specified value `true_value`. -#' -#' @param false_value False value -#' -#' For all other subjects in `dataset_adsl` without an event, `new_var` is set to -#' the specified value `false_value`. -#' -#' @param mode Selection mode (first or last) -#' -#' If `"first"` is specified, the first observation of each subject is selected. -#' If `"last"` is specified, the last observation of each subject is selected. -#' -#' *Permitted Values*: `"first"`, `"last"` -#' -#' @param set_values_to Variables to set -#' -#' A named list returned by `exprs()` defining the variables to be set for the -#' new parameter, e.g. `exprs(PARAMCD = "PD", PARAM = "Disease Progression")` -#' is expected. The values must be symbols, character strings, numeric values, -#' `NA`, or an expression. Note, if you require a date or datetime variable to -#' be populated, this needs to be defined here. -#' -#' @param subject_keys Variables to uniquely identify a subject -#' -#' A list of symbols created using `exprs()` is expected. -#' -#' @param check_type Check uniqueness? -#' -#' If `"warning"` or `"error"` is specified, a message is issued if the -#' observations of the source dataset (`dataset_source`) restricted by -#' `filter_source` are not unique with respect to the subject keys -#' (`subject_key` argument) and `order`. -#' -#' *Permitted Values*: `"none"`, `"warning"`, `"error"` -#' -#' @details -#' 1. The source dataset (`dataset_source`) is restricted to observations fulfilling -#' `filter_source`. -#' 1. For each subject (with respect to the variables specified for the -#' `subject_keys` argument) either the first or last observation from the restricted -#' source dataset is selected. This is depending on `mode`, (with respect to `order`, -#' if applicable) where the event condition (`filter_source` argument) is fulfilled. -#' 1. For each observation in `dataset_adsl` a new observation is created. For -#' subjects with event `new_var` is set to `true_value`. For all other -#' subjects `new_var` is set to `false_value`. -#' For subjects with event all variables from `dataset_source` are kept. For -#' subjects without event all variables which are in both `dataset_adsl` and -#' `dataset_source` are kept. -#' 1. The variables specified by the `set_values_to` argument are added to -#' the new observations. -#' 1. The new observations are added to input dataset. -#' -#' -#' @return The input dataset with a new parameter indicating if and when an -#' event occurred -#' -#' @family deprecated -#' @keywords deprecated -#' -#' @export -derive_param_extreme_event <- function(dataset = NULL, - dataset_adsl, - dataset_source, - filter_source, - order = NULL, - new_var = NULL, - true_value = "Y", - false_value = "N", - mode = "first", - subject_keys = get_admiral_option("subject_keys"), - set_values_to, - check_type = "warning") { - deprecate_stop("0.11.0", "derive_param_extreme_event()", "derive_extreme_records()") -} diff --git a/R/derive_param_extreme_record.R b/R/derive_param_extreme_record.R index d14753b984..e55431b7ea 100644 --- a/R/derive_param_extreme_record.R +++ b/R/derive_param_extreme_record.R @@ -4,7 +4,7 @@ #' source datasets, based on user-defined filter, order and by group criteria. #' All variables of the selected observation are kept. #' -#' @param dataset Input dataset +#' @param dataset `r roxygen_param_dataset()` #' #' @param sources Sources #' diff --git a/R/derive_param_framingham.R b/R/derive_param_framingham.R index 7f10bb234f..5186206151 100644 --- a/R/derive_param_framingham.R +++ b/R/derive_param_framingham.R @@ -4,10 +4,9 @@ #' Adds a record for framingham score (FCVD101) for each by group #' (e.g., subject and visit) where the source parameters are available. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` parameter, `PARAMCD`, and -#' `AVAL` are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` +#' `PARAMCD`, and `AVAL` are expected as well. #' #' The variable specified by `by_vars` and `PARAMCD` must be a unique key of #' the input dataset after restricting it by the filter condition (`filter` diff --git a/R/derive_param_tte.R b/R/derive_param_tte.R index 9b5069813d..db870381d1 100644 --- a/R/derive_param_tte.R +++ b/R/derive_param_tte.R @@ -2,9 +2,8 @@ #' #' Add a time-to-event parameter to the input dataset. #' -#' @param dataset Input dataset -#' -#' The `PARAMCD` variable is expected. +#' @param dataset `r roxygen_param_dataset()` +#' `PARAMCD` is expected. #' #' @param dataset_adsl ADSL input dataset #' diff --git a/R/derive_param_wbc_abs.R b/R/derive_param_wbc_abs.R index 60ec791326..5dc7a1e79d 100644 --- a/R/derive_param_wbc_abs.R +++ b/R/derive_param_wbc_abs.R @@ -4,10 +4,9 @@ #' #' Add a parameter by converting lab differentials from fraction or percentage to absolute values #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` argument, `PARAMCD`, and `AVAL` -#' are expected to be present. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` +#' `PARAMCD`, and `AVAL` are expected as well. #' #' The variable specified by `by_vars` and `PARAMCD` must be a unique key of #' the input dataset, and to the parameters specified by `wbc_code` and `diff_code`. diff --git a/R/derive_summary_records.R b/R/derive_summary_records.R index 9418e0cafd..ced3a0093e 100644 --- a/R/derive_summary_records.R +++ b/R/derive_summary_records.R @@ -11,7 +11,7 @@ #' retain those common values in the newly derived records. Otherwise new value #' will be set to `NA`. #' -#' @param dataset A data frame. +#' @param dataset `r roxygen_param_dataset(expected_vars = c("by_vars", "analysis_var"))` #' #' @param by_vars Variables to consider for generation of groupwise summary #' records. Providing the names of variables in [exprs()] will create a @@ -29,111 +29,87 @@ #' + `filter = (dplyr::n() > 2)` will filter n count of `by_vars` greater #' than 2. #' -#' @param analysis_var Analysis variable. -#' -#' @param summary_fun Function that takes as an input the `analysis_var` and -#' performs the calculation. -#' This can include built-in functions as well as user defined functions, -#' for example `mean` or `function(x) mean(x, na.rm = TRUE)`. -#' -#' @param set_values_to Variables to be set -#' -#' The specified variables are set to the specified values for the new -#' observations. -#' -#' A list of variable name-value pairs is expected. -#' + LHS refers to a variable. -#' + RHS refers to the values to set to the variable. This can be a string, a -#' symbol, a numeric value, an expression, or `NA`, e.g., `exprs(PARAMCD = -#' "TDOSE", PARCAT1 = "OVERALL")`. +#' @inheritParams get_summary_records #' #' @return A data frame with derived records appended to original dataset. #' #' @family der_prm_bds_findings #' @keywords der_prm_bds_findings #' -#' @seealso `get_summary_records()` +#' @seealso [get_summary_records()], [derive_var_merged_summary()] #' #' @export #' #' @examples #' library(tibble) -#' library(dplyr, warn.conflicts = TRUE) +#' library(dplyr) #' #' adeg <- tribble( -#' ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, -#' "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, "", -#' "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, "", -#' "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, "", -#' "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:45", 384, "Placebo", -#' "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", -#' "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", -#' "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:45", 385, "Placebo", -#' "XYZ-1001", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", -#' "XYZ-1001", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", -#' "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, "", -#' "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, "", -#' "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, "", -#' "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:50", 401, "Active 20mg", -#' "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", -#' "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", -#' "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:50", 412, "Active 20mg", -#' "XYZ-1002", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", -#' "XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg", -#' ) +#' ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, +#' "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_, +#' "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, NA_character_, +#' "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, NA_character_, +#' "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:45", 384, "Placebo", +#' "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", +#' "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", +#' "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:45", 385, "Placebo", +#' "XYZ-1001", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", +#' "XYZ-1001", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", +#' "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, NA_character_, +#' "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, NA_character_, +#' "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, NA_character_, +#' "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:50", 401, "Active 20mg", +#' "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", +#' "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", +#' "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:50", 412, "Active 20mg", +#' "XYZ-1002", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", +#' "XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg" +#' ) %>% +#' mutate( +#' ADTM = convert_dtc_to_dtm(EGDTC) +#' ) #' #' # Summarize the average of the triplicate ECG interval values (AVAL) #' derive_summary_records( #' adeg, #' by_vars = exprs(USUBJID, PARAM, AVISIT), -#' analysis_var = AVAL, -#' summary_fun = function(x) mean(x, na.rm = TRUE), -#' set_values_to = exprs(DTYPE = "AVERAGE") -#' ) -#' -#' advs <- tribble( -#' ~USUBJID, ~VSSEQ, ~PARAM, ~AVAL, ~VSSTRESU, ~VISIT, ~VSDTC, -#' "XYZ-001-001", 1164, "Weight", 99, "kg", "Screening", "2018-03-19", -#' "XYZ-001-001", 1165, "Weight", 101, "kg", "Run-In", "2018-03-26", -#' "XYZ-001-001", 1166, "Weight", 100, "kg", "Baseline", "2018-04-16", -#' "XYZ-001-001", 1167, "Weight", 94, "kg", "Week 24", "2018-09-30", -#' "XYZ-001-001", 1168, "Weight", 92, "kg", "Week 48", "2019-03-17", -#' "XYZ-001-001", 1169, "Weight", 95, "kg", "Week 52", "2019-04-14", -#' ) +#' set_values_to = exprs( +#' AVAL = mean(AVAL, na.rm = TRUE), +#' DTYPE = "AVERAGE" +#' ) +#' ) %>% +#' arrange(USUBJID, AVISIT) #' -#' # Set new values to any variable. Here, `DTYPE = MAXIMUM` refers to `max()` records -#' # and `DTYPE = AVERAGE` refers to `mean()` records. +#' # Derive more than one summary variable #' derive_summary_records( -#' advs, -#' by_vars = exprs(USUBJID, PARAM), -#' analysis_var = AVAL, -#' summary_fun = max, -#' set_values_to = exprs(DTYPE = "MAXIMUM") -#' ) %>% -#' derive_summary_records( -#' by_vars = exprs(USUBJID, PARAM), -#' analysis_var = AVAL, -#' summary_fun = mean, -#' set_values_to = exprs(DTYPE = "AVERAGE") +#' adeg, +#' by_vars = exprs(USUBJID, PARAM, AVISIT), +#' set_values_to = exprs( +#' AVAL = mean(AVAL), +#' ADTM = max(ADTM), +#' DTYPE = "AVERAGE" #' ) +#' ) %>% +#' arrange(USUBJID, AVISIT) %>% +#' select(-EGSEQ, -TRTA) #' #' # Sample ADEG dataset with triplicate record for only AVISIT = 'Baseline' #' adeg <- tribble( -#' ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, -#' "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, "", -#' "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, "", -#' "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, "", -#' "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", -#' "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", -#' "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", -#' "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", -#' "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, "", -#' "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, "", -#' "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, "", -#' "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", -#' "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", -#' "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", -#' "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg", +#' ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, +#' "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_, +#' "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, NA_character_, +#' "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, NA_character_, +#' "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", +#' "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", +#' "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", +#' "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", +#' "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, NA_character_, +#' "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, NA_character_, +#' "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, NA_character_, +#' "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", +#' "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", +#' "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", +#' "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg" #' ) #' #' # Compute the average of AVAL only if there are more than 2 records within the @@ -142,25 +118,36 @@ #' adeg, #' by_vars = exprs(USUBJID, PARAM, AVISIT), #' filter = n() > 2, -#' analysis_var = AVAL, -#' summary_fun = function(x) mean(x, na.rm = TRUE), -#' set_values_to = exprs(DTYPE = "AVERAGE") -#' ) +#' set_values_to = exprs( +#' AVAL = mean(AVAL, na.rm = TRUE), +#' DTYPE = "AVERAGE" +#' ) +#' ) %>% +#' arrange(USUBJID, AVISIT) derive_summary_records <- function(dataset, by_vars, filter = NULL, analysis_var, summary_fun, - set_values_to = NULL) { + set_values_to) { assert_vars(by_vars) - analysis_var <- assert_symbol(enexpr(analysis_var)) filter <- assert_filter_cond(enexpr(filter), optional = TRUE) - assert_s3_class(summary_fun, "function") assert_data_frame( dataset, - required_vars = expr_c(by_vars, analysis_var) + required_vars = by_vars ) - assert_varval_list(set_values_to, optional = TRUE) + assert_varval_list(set_values_to) + + if (!missing(analysis_var) || !missing(summary_fun)) { + deprecate_warn( + "1.0.0", + I("derive_summary_records(anaylsis_var = , summary_fun = )"), + "derive_summary_records(set_values_to = )" + ) + analysis_var <- assert_symbol(enexpr(analysis_var)) + assert_s3_class(summary_fun, "function") + set_values_to <- exprs(!!analysis_var := {{ summary_fun }}(!!analysis_var), !!!set_values_to) + } # Summarise the analysis value and bind to the original dataset bind_rows( @@ -169,8 +156,6 @@ derive_summary_records <- function(dataset, dataset, by_vars = by_vars, filter = !!filter, - analysis_var = !!analysis_var, - summary_fun = summary_fun, set_values_to = set_values_to ) ) diff --git a/R/derive_var_analysis_ratio.R b/R/derive_var_analysis_ratio.R index 98a35cce18..7a41ac6015 100644 --- a/R/derive_var_analysis_ratio.R +++ b/R/derive_var_analysis_ratio.R @@ -2,7 +2,8 @@ #' #' Derives a ratio variable for a BDS dataset based on user specified variables. #' -#' @param dataset Input dataset +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("numer_var", "denom_var"))` #' #' @param numer_var Variable containing numeric values to be used in the numerator of #' the ratio calculation. diff --git a/R/derive_var_anrind.R b/R/derive_var_anrind.R index 909e5b452c..ae37f01591 100644 --- a/R/derive_var_anrind.R +++ b/R/derive_var_anrind.R @@ -1,6 +1,10 @@ #' Derive Reference Range Indicator #' -#' @param dataset The input dataset +#' @param dataset +#' `r roxygen_param_dataset()` +#' `ANRLO`, `ANRHI`, and `AVAL` are expected and if `use_a1hia1lo` is set to `TRUE`, +#' `A1LO` and `A1H1` are expected as well. +#' #' @param use_a1hia1lo A logical value indicating whether to use `A1H1` and `A1LO` in #' the derivation of `ANRIND`. #' diff --git a/R/derive_var_atoxgr.R b/R/derive_var_atoxgr.R index 1addcf86f2..7cb8467250 100644 --- a/R/derive_var_atoxgr.R +++ b/R/derive_var_atoxgr.R @@ -3,9 +3,8 @@ #' @description #' Derives a character lab grade based on severity/toxicity criteria. #' -#' @param dataset Input data set -#' -#' The columns specified by `tox_description_var` parameter is expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("tox_description_var"))` #' #' @param new_var Name of the character grade variable to create, for example, `ATOXGRH` #' or `ATOXGRL`. @@ -246,10 +245,9 @@ derive_var_atoxgr_dir <- function(dataset, #' #' Derives character lab grade based on high and low severity/toxicity grade(s). #' -#' @param dataset Input data set -#' -#' The columns `ATOXGRL`, `ATOXGRH` and specified by `lotox_description_var`, -#' and `hitox_description_var` parameters are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("lotox_description_var", "hitox_description_var"))` +#' `ATOXGRL`, and `ATOXGRH` are expected as well. #' #' @param lotox_description_var Variable containing the toxicity grade description #' for low values, eg. "Anemia" diff --git a/R/derive_var_base.R b/R/derive_var_base.R index 5f88f582bf..af60e1d676 100644 --- a/R/derive_var_base.R +++ b/R/derive_var_base.R @@ -4,7 +4,7 @@ #' #' **Note:** This is a wrapper function for the more generic `derive_vars_merged()`. #' -#' @param dataset The input dataset +#' @param dataset `r roxygen_param_dataset(expected_vars = c("by_vars", "source_var"))` #' #' @param by_vars Grouping variables uniquely identifying a set #' of records for which to calculate `new_var` diff --git a/R/derive_var_basetype.R b/R/derive_var_basetype.R deleted file mode 100644 index 5c4714593b..0000000000 --- a/R/derive_var_basetype.R +++ /dev/null @@ -1,46 +0,0 @@ -#' Derive Basetype Variable -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `derive_basetype_records()` instead. -#' -#' Baseline Type `BASETYPE` is needed when there is more than one definition of -#' baseline for a given Analysis Parameter `PARAM` in the same dataset. For a -#' given parameter, if Baseline Value `BASE` is populated, and there is more than -#' one definition of baseline, then `BASETYPE` must be non-null on all records of -#' any type for that parameter. Each value of `BASETYPE` refers to a definition of -#' baseline that characterizes the value of `BASE` on that row. Please see -#' section 4.2.1.6 of the ADaM Implementation Guide, version 1.3 for further -#' background. -#' -#' Adds the `BASETYPE` variable to a dataset and duplicates records based upon -#' the provided conditions. -#' -#' @param dataset Input dataset -#' -#' The columns specified in the expressions inside `basetypes` are required. -#' -#' @param basetypes A *named* list of expressions created using the -#' `rlang::exprs()` function -#' -#' The names corresponds to the values of the newly created `BASETYPE` variables -#' and the expressions are used to subset the input dataset. -#' -#' @details -#' For each element of `basetypes` the input dataset is subset based upon -#' the provided expression and the `BASETYPE` variable is set to the name of the -#' expression. Then, all subsets are stacked. Records which do not match any -#' condition are kept and `BASETYPE` is set to `NA`. -#' -#' @return The input dataset with variable `BASETYPE` added -#' -#' -#' @family deprecated -#' -#' @keywords deprecated -#' -#' @export -derive_var_basetype <- function(dataset, basetypes) { - deprecate_stop("0.11.0", "derive_var_basetype()", "derive_basetype_records()") -} diff --git a/R/derive_var_chg.R b/R/derive_var_chg.R index 3a0ca93f03..0d913d4437 100644 --- a/R/derive_var_chg.R +++ b/R/derive_var_chg.R @@ -4,6 +4,8 @@ #' #' @param dataset The input dataset. Required variables are `AVAL` and #' `BASE`. +#' @param dataset +#' `r roxygen_param_dataset()` `AVAL` and `BASE` are expected. #' #' @details #' Change from baseline is calculated by subtracting the baseline value diff --git a/R/derive_var_dthcaus.R b/R/derive_var_dthcaus.R index ed9c74f37c..e0e0bceca2 100644 --- a/R/derive_var_dthcaus.R +++ b/R/derive_var_dthcaus.R @@ -2,9 +2,8 @@ #' #' Derive death cause (`DTHCAUS`) and add traceability variables if required. #' -#' @param dataset Input dataset. -#' -#' The variables specified by `subject_keys` are required. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("subject_keys"))` #' #' @param source_datasets A named `list` containing datasets in which to search for the #' death cause @@ -317,7 +316,7 @@ dthcaus_source <- function(dataset_name, set_values_to = NULL, traceability_vars = NULL) { if (!is.null(traceability_vars)) { - deprecate_warn( + deprecate_stop( "0.12.0", "dthcaus_source(traceability_vars = )", "dthcaus_source(set_values_to = )" diff --git a/R/derive_var_extreme_date.R b/R/derive_var_extreme_date.R index 6cc7aab1a6..c4611189c6 100644 --- a/R/derive_var_extreme_date.R +++ b/R/derive_var_extreme_date.R @@ -3,9 +3,8 @@ #' Add the first or last datetime from multiple sources to the dataset, e.g., #' the last known alive datetime (`LSTALVDTM`). #' -#' @param dataset Input dataset -#' -#' The variables specified by `subject_keys` are required. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("subject_keys"))` #' #' @param new_var Name of variable to create #' @@ -621,7 +620,7 @@ date_source <- function(dataset_name, traceability_vars = NULL, set_values_to = NULL) { if (!is.null(traceability_vars)) { - deprecate_warn( + deprecate_stop( "0.12.0", "date_source(traceability_vars = )", "date_source(set_values_to = )" diff --git a/R/derive_var_extreme_flag.R b/R/derive_var_extreme_flag.R index 8cca038477..f5c52f658c 100644 --- a/R/derive_var_extreme_flag.R +++ b/R/derive_var_extreme_flag.R @@ -2,9 +2,8 @@ #' #' Add a variable flagging the first or last observation within each by group #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` parameter are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` #' #' @param order Sort order #' @@ -15,8 +14,8 @@ #' #' @param new_var Variable to add #' -#' The specified variable is added to the output dataset. It is set to `"Y"` -#' for the first or last observation (depending on the mode) of each by group. +#' The specified variable is added to the output dataset. It is set to the value +#' set in `true_value` for the first or last observation (depending on the mode) of each by group. #' #' Permitted Values: list of name-value pairs #' @@ -26,6 +25,20 @@ #' #' Permitted Values: `"first"`, `"last"` #' +#' @param true_value True value +#' +#' The value for the specified variable `new_var`, applicable to +#' the first or last observation (depending on the mode) of each by group. +#' +#' Permitted Values: An atomic scalar +#' +#' @param false_value False value +#' +#' The value for the specified variable `new_var`, NOT applicable to +#' the first or last observation (depending on the mode) of each by group. +#' +#' Permitted Values: An atomic scalar +#' #' @param flag_all Flag setting #' #' A logical value where if set to `TRUE`, all records are flagged @@ -233,6 +246,8 @@ derive_var_extreme_flag <- function(dataset, order, new_var, mode, + true_value = "Y", + false_value = NA_character_, flag_all = FALSE, check_type = "warning") { new_var <- assert_symbol(enexpr(new_var)) @@ -240,6 +255,8 @@ derive_var_extreme_flag <- function(dataset, assert_expr_list(order) assert_data_frame(dataset, required_vars = exprs(!!!by_vars, !!!extract_vars(order))) mode <- assert_character_scalar(mode, values = c("first", "last"), case_sensitive = FALSE) + assert_atomic_vector(true_value, optional = TRUE) + assert_atomic_vector(false_value, optional = TRUE) flag_all <- assert_logical_scalar(flag_all) check_type <- assert_character_scalar( check_type, @@ -264,11 +281,11 @@ derive_var_extreme_flag <- function(dataset, if (mode == "first") { data <- data %>% - mutate(!!new_var := if_else(!!tmp_obs_nr == 1, "Y", NA_character_)) + mutate(!!new_var := if_else(!!tmp_obs_nr == 1, true_value, false_value)) } else { data <- data %>% group_by(!!!by_vars) %>% - mutate(!!new_var := if_else(!!tmp_obs_nr == n(), "Y", NA_character_)) %>% + mutate(!!new_var := if_else(!!tmp_obs_nr == n(), true_value, false_value)) %>% ungroup() } diff --git a/R/derive_var_joined_exist_flag.R b/R/derive_var_joined_exist_flag.R index d96e97476f..fece51a587 100644 --- a/R/derive_var_joined_exist_flag.R +++ b/R/derive_var_joined_exist_flag.R @@ -10,10 +10,8 @@ #' response value can be confirmed by an other assessment. This is commonly #' used in endpoints such as best overall response. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` and `join_vars` parameter are -#' expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars", "join_vars"))` #' #' @param by_vars By variables #' @@ -388,204 +386,3 @@ derive_var_joined_exist_flag <- function(dataset, ) %>% remove_tmp_vars() } - -#' Derive Confirmation Flag -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `derive_var_joined_exist_flag()` instead. -#' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` and `join_vars` parameter are -#' expected. -#' -#' @param by_vars By variables -#' -#' The specified variables are used as by variables for joining the input -#' dataset with itself. -#' -#' @param order Order -#' -#' The observations are ordered by the specified order. -#' -#' @param new_var New variable -#' -#' The specified variable is added to the input dataset. -#' -#' @param tmp_obs_nr_var Temporary observation number -#' -#' The specified variable is added to the input dataset and set to the -#' observation number with respect to `order`. For each by group (`by_vars`) -#' the observation number starts with `1`. The variable can be used in the -#' conditions (`filter`, `first_cond`). It is not included in the output -#' dataset. It can be used to flag consecutive observations or the last -#' observation (see last example below). -#' -#' @param join_vars Variables to keep from joined dataset -#' -#' The variables needed from the other observations should be specified -#' for this parameter. The specified variables are added to the joined dataset -#' with suffix ".join". For example to flag all observations with `AVALC == -#' "Y"` and `AVALC == "Y"` for at least one subsequent visit `join_vars = -#' exprs(AVALC, AVISITN)` and `filter = AVALC == "Y" & AVALC.join == "Y" & -#' AVISITN < AVISITN.join` could be specified. -#' -#' The `*.join` variables are not included in the output dataset. -#' -#' @param join_type Observations to keep after joining -#' -#' The argument determines which of the joined observations are kept with -#' respect to the original observation. For example, if `join_type = "after"` -#' is specified all observations after the original observations are kept. -#' -#' For example for confirmed response or BOR in the oncology setting or -#' confirmed deterioration in questionnaires the confirmatory assessment must -#' be after the assessment to be flagged. Thus `join_type = "after"` could be -#' used. -#' -#' Whereas, sometimes you might allow for confirmatory observations to occur -#' prior to the observation to be flagged. For example, to flag AEs occurring -#' on or after seven days before a COVID AE. Thus `join_type = "all"` could be -#' used. -#' -#' *Permitted Values:* `"before"`, `"after"`, `"all"` -#' -#' @param first_cond Condition for selecting range of data -#' -#' If this argument is specified, the other observations are restricted up to -#' the first observation where the specified condition is fulfilled. If the -#' condition is not fulfilled for any of the other observations, no -#' observations are considered, i.e., the observation is not flagged. -#' -#' This parameter should be specified if `filter` contains summary functions -#' which should not apply to all observations but only up to the confirmation -#' assessment. For an example see the third example below. -#' -#' @param filter Condition for selecting observations -#' -#' The filter is applied to the joined dataset for flagging the confirmed -#' observations. The condition can include summary functions. The joined -#' dataset is grouped by the original observations. I.e., the summary function -#' are applied to all observations up to the confirmation observation. For -#' example, `filter = AVALC == "CR" & all(AVALC.join %in% c("CR", "NE")) & -#' count_vals(var = AVALC.join, val = "NE") <= 1` selects observations with -#' response "CR" and for all observations up to the confirmation observation -#' the response is "CR" or "NE" and there is at most one "NE". -#' -#' @param check_type Check uniqueness? -#' -#' If `"warning"` or `"error"` is specified, the specified message is issued -#' if the observations of the input dataset are not unique with respect to the -#' by variables and the order. -#' -#' *Default:* `"warning"` -#' -#' *Permitted Values:* `"none"`, `"warning"`, `"error"` -#' -#' @param true_value Value of `new_var` for flagged observations -#' -#' *Default*: `"Y"` -#' -#' @param false_value Value of `new_var` for observations not flagged -#' -#' *Default*: `NA_character_` -#' -#' @details -#' The following steps are performed to produce the output dataset. -#' -#' ## Step 1 -#' -#' The input dataset is joined with itself by the variables specified for -#' `by_vars`. From the right hand side of the join only the variables -#' specified for `join_vars` are kept. The suffix ".join" is added to these -#' variables. -#' -#' For example, for `by_vars = USUBJID`, `join_vars = exprs(AVISITN, AVALC)` and input dataset -#' -#' ```{r eval=FALSE} -#' # A tibble: 2 x 4 -#' USUBJID AVISITN AVALC AVAL -#' -#' 1 1 Y 1 -#' 1 2 N 0 -#' ``` -#' -#' the joined dataset is -#' -#' ```{r eval=FALSE} -#' A tibble: 4 x 6 -#' USUBJID AVISITN AVALC AVAL AVISITN.join AVALC.join -#' -#' 1 1 Y 1 1 Y -#' 1 1 Y 1 2 N -#' 1 2 N 0 1 Y -#' 1 2 N 0 2 N -#' ``` -#' -#' ## Step 2 -#' -#' The joined dataset is restricted to observations with respect to -#' `join_type` and `order`. -#' -#' The dataset from the example in the previous step with `join_type = -#' "after"` and `order = exprs(AVISITN)` is restricted to -#' -#' ```{r eval=FALSE} -#' A tibble: 4 x 6 -#' USUBJID AVISITN AVALC AVAL AVISITN.join AVALC.join -#' -#' 1 1 Y 1 2 N -#' ``` -#' -#' ## Step 3 -#' -#' If `first_cond` is specified, for each observation of the input dataset the -#' joined dataset is restricted to observations up to the first observation -#' where `first_cond` is fulfilled (the observation fulfilling the condition -#' is included). If for an observation of the input dataset the condition is -#' not fulfilled, the observation is removed. -#' -#' ## Step 4 -#' -#' The joined dataset is grouped by the observations from the input dataset -#' and restricted to the observations fulfilling the condition specified by -#' `filter`. -#' -#' ## Step 5 -#' -#' The first observation of each group is selected -#' -#' ## Step 6 -#' -#' The variable specified by `new_var` is added to the input dataset. It is -#' set to `true_value` for all observations which were selected in the -#' previous step. For the other observations it is set to `false_value`. -#' -#' @return The input dataset with the variable specified by `new_var` added. -#' -#' -#' @keywords deprecated -#' @family deprecated -#' -#' @export -#' -derive_var_confirmation_flag <- function(dataset, - by_vars, - order, - new_var, - tmp_obs_nr_var = NULL, - join_vars, - join_type, - first_cond = NULL, - filter, - true_value = "Y", - false_value = NA_character_, - check_type = "warning") { - deprecate_stop( - "0.10.0", - "derive_var_confirmation_flag()", - details = "Please use `derive_var_joined_exist_flag()` instead." - ) -} diff --git a/R/derive_var_last_dose_amt.R b/R/derive_var_last_dose_amt.R deleted file mode 100644 index f16f027bbe..0000000000 --- a/R/derive_var_last_dose_amt.R +++ /dev/null @@ -1,44 +0,0 @@ -#' Derive Last Dose Amount -#' -#' @description Add a variable for dose amount from the last dose to the input dataset. -#' -#' **Note:** This is a wrapper function for the function `derive_vars_last_dose()`. -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `derive_vars_joined()` instead. -#' -#' @inheritParams derive_vars_last_dose -#' @param new_var The new variable added to `dataset`. -#' @param dose_var The EX source dose amount variable. Defaults to `EXDOSE`. -#' -#' @details The last dose amount is derived as the dose amount where the maximum `dose_date` is -#' lower to or equal to the `analysis_date` per `by_vars` for each observation in `dataset`. -#' -#' If dose information is aggregated (i.e. is a dosing frequency other than `"ONCE"` -#' over a period defined by a start and end date) the function -#' `create_single_dose_dataset()` can be used to generate single doses from -#' aggregate dose information and satisfy `single_dose_condition`. -#' -#' @return Input dataset with additional column `new_var`. -#' -#' -#' @family deprecated -#' @keywords deprecated -#' -#' @export -#' -derive_var_last_dose_amt <- function(dataset, - dataset_ex, - filter_ex = NULL, - by_vars = exprs(STUDYID, USUBJID), - dose_id = exprs(), - dose_date, - analysis_date, - single_dose_condition = (EXDOSFRQ == "ONCE"), - new_var, - dose_var = EXDOSE, - traceability_vars = NULL) { - deprecate_stop("0.11.0", "derive_var_last_dose_amt()", "derive_vars_joined()") -} diff --git a/R/derive_var_last_dose_date.R b/R/derive_var_last_dose_date.R deleted file mode 100644 index fe5152a354..0000000000 --- a/R/derive_var_last_dose_date.R +++ /dev/null @@ -1,48 +0,0 @@ -#' Derive Last Dose Date-Time -#' -#' @description Add a variable for the dose date or datetime of the last dose to -#' the input dataset. -#' -#' **Note:** This is a wrapper function for the function `derive_vars_last_dose()`. -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `derive_vars_joined()` instead. -#' -#' @inheritParams derive_vars_last_dose -#' @param new_var The new date or datetime variable added to `dataset`. -#' @param output_datetime Display `new_var` as datetime or as date only. Defaults to `TRUE`. -#' -#' @details The last dose date is derived as the maximum dose date where the -#' `dose_date` is lower to or equal to the `analysis_date` per `by_vars` for -#' each observation in `dataset`. When `output_datetime` is `TRUE` and time is -#' missing, then the last dose date time is imputed to `00:00:00`. However, if -#' date is missing, then no imputation is done. -#' -#' If dose information is aggregated (i.e. is a dosing frequency other than `"ONCE"` -#' over a period defined by a start and end date) the function -#' `create_single_dose_dataset()` can be used to generate single doses from -#' aggregate dose information and satisfy `single_dose_condition`. -#' -#' @return Input dataset with additional column `new_var`. -#' -#' -#' @family deprecated -#' @keywords deprecated -#' -#' @export -#' -derive_var_last_dose_date <- function(dataset, - dataset_ex, - filter_ex = NULL, - by_vars = exprs(STUDYID, USUBJID), - dose_id = exprs(), - dose_date, - analysis_date, - single_dose_condition = (EXDOSFRQ == "ONCE"), - new_var, - output_datetime = TRUE, - traceability_vars = NULL) { - deprecate_stop("0.11.0", "derive_var_last_dose_date()", "derive_vars_joined()") -} diff --git a/R/derive_var_last_dose_grp.R b/R/derive_var_last_dose_grp.R deleted file mode 100644 index 23dbf86bb5..0000000000 --- a/R/derive_var_last_dose_grp.R +++ /dev/null @@ -1,60 +0,0 @@ -#' Derive Last Dose with User-Defined Groupings -#' -#' @description Add a variable for user-defined dose grouping of the last dose -#' to the input dataset. -#' -#' **Note:** This is a wrapper function for the function `derive_vars_last_dose()`. -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `derive_vars_joined()` instead. -#' -#' @inheritParams derive_vars_last_dose -#' @param new_var The output variable defined by the user. -#' @param grp_brks User supplied breaks to apply to groups. -#' Refer to `breaks` parameter in `cut()` for details. -#' @param grp_lbls User supplied labels to apply to groups. -#' Refer to `labels` parameter in `cut()` for details. -#' @param dose_var The source dose amount variable. Defaults to `EXDOSE`. -#' @param include_lowest logical, indicating if a value equal to the lowest -#' (or highest, for right = FALSE) ‘breaks’ value should be included. -#' Refer to `include.lowest` parameter in `cut()` for details. -#' @param right Logical, indicating if the intervals should be closed on the right -#' (and open on the left) or vice versa. -#' Refer to `right` parameter in `cut()` for details. -#' -#' @details Last dose is the dose with maximum `dose_date` that is lower to or equal to the -#' `analysis_date` per `by_vars` for each observation in `dataset`. -#' The last dose group is then derived by user-defined grouping, which groups -#' `dose_var` as specified in `grp_brks`, and returns `grp_lbls` as the values for `new_var`. -#' -#' If dose information is aggregated (i.e. is a dosing frequency other than `"ONCE"` -#' over a period defined by a start and end date) the function -#' `create_single_dose_dataset()` can be used to generate single doses from -#' aggregate dose information and satisfy `single_dose_condition`. -#' @return Input dataset with additional column `new_var`. -#' -#' -#' @family deprecated -#' @keywords deprecated -#' -#' @export -#' -derive_var_last_dose_grp <- function(dataset, - dataset_ex, - filter_ex = NULL, - by_vars = exprs(STUDYID, USUBJID), - dose_id = exprs(), - dose_date, - analysis_date, - single_dose_condition = (EXDOSFRQ == "ONCE"), - new_var, - grp_brks, - grp_lbls, - include_lowest = TRUE, - right = TRUE, - dose_var = EXDOSE, - traceability_vars = NULL) { - deprecate_stop("0.11.0", "derive_var_last_dose_grp()", "derive_vars_joined()") -} diff --git a/R/derive_var_obs_number.R b/R/derive_var_obs_number.R index ffa425263f..46bcbef97d 100644 --- a/R/derive_var_obs_number.R +++ b/R/derive_var_obs_number.R @@ -2,10 +2,8 @@ #' #' Adds a variable numbering the observations within each by group #' -#' @param dataset Input dataset -#' -#' The variables specified by the `order` and the `by_vars` parameter are -#' expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars", "order"))` #' #' @param by_vars Grouping variables #' diff --git a/R/derive_var_ontrtfl.R b/R/derive_var_ontrtfl.R index f5d53b1513..64eab8116b 100644 --- a/R/derive_var_ontrtfl.R +++ b/R/derive_var_ontrtfl.R @@ -4,7 +4,7 @@ #' assessment date (e.g `ADT`) or event start and end dates (e.g. #' `ASTDT`/`AENDT`). #' -#' @param dataset Input dataset. +#' @param dataset `r roxygen_param_dataset()` #' #' Required columns are `start_date`, `end_date`, `ref_start_date` and #' `ref_end_date`. @@ -190,7 +190,7 @@ derive_var_ontrtfl <- function(dataset, if (is.null(span_period) || span_period %in% c("Y", "y")) { # replace span_period with lgl version span_period <- !is.null(span_period) - deprecate_warn( + deprecate_stop( when = "0.12.0", what = "admiral::derive_var_ontrtfl(span_period = 'must be TRUE or FALSE')", details = diff --git a/R/derive_var_pchg.R b/R/derive_var_pchg.R index 035ab479f6..03ac7e8c30 100644 --- a/R/derive_var_pchg.R +++ b/R/derive_var_pchg.R @@ -2,8 +2,8 @@ #' #' Derive percent change from baseline (`PCHG`) in a BDS dataset #' -#' @param dataset The input dataset. Required variables are `AVAL` and -#' `BASE`. +#' @param dataset `r roxygen_param_dataset()` +#' `AVAL` and `BASE` are expected. #' #' @details #' Percent change from baseline is calculated by dividing change from diff --git a/R/derive_var_relative_flag.R b/R/derive_var_relative_flag.R index 42883f1c45..a2295d85ce 100644 --- a/R/derive_var_relative_flag.R +++ b/R/derive_var_relative_flag.R @@ -5,10 +5,8 @@ #' called to flag for each subject all observations before the first disease #' progression or to flag all AEs after a specific AE. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `order` and the `by_vars` argument are -#' expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars", "order"))` #' #' @param by_vars Grouping variables #' diff --git a/R/derive_var_shift.R b/R/derive_var_shift.R index 1305cfa218..38dfe85e8d 100644 --- a/R/derive_var_shift.R +++ b/R/derive_var_shift.R @@ -4,9 +4,8 @@ #' values based on user-defined pairing, e.g., shift from baseline to #' analysis value, shift from baseline grade to analysis grade, ... #' -#' @param dataset Input dataset -#' -#' The columns specified by `from_var` and the `to_var` parameters are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("from_var", "to_var"))` #' #' @param new_var Name of the character shift variable to create. #' @@ -78,7 +77,7 @@ derive_var_shift <- function(dataset, sep_val = " to ") { ### BEGIN DEPRECATION if (!missing(na_val)) { - deprecate_warn("0.12.0", "derive_var_shift(na_val = )", "derive_var_shift(missing_value = )") + deprecate_stop("0.12.0", "derive_var_shift(na_val = )", "derive_var_shift(missing_value = )") missing_value <- na_val } ### END DEPRECATION diff --git a/R/derive_var_trtdurd.R b/R/derive_var_trtdurd.R index d2e3e46042..88c36c0c00 100644 --- a/R/derive_var_trtdurd.R +++ b/R/derive_var_trtdurd.R @@ -4,10 +4,8 @@ #' #' **Note:** This is a wrapper function for the more generic `derive_vars_duration()`. #' -#' @param dataset Input dataset -#' -#' The columns specified by the `start_date` and the `end_date` parameter are -#' expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("start_date", "end_date"))` #' #' @param start_date The start date #' diff --git a/R/derive_var_trtemfl.R b/R/derive_var_trtemfl.R index dc88db41db..ef09e50296 100644 --- a/R/derive_var_trtemfl.R +++ b/R/derive_var_trtemfl.R @@ -2,7 +2,7 @@ #' #' Derive treatment emergent analysis flag (e.g., `TRTEMFL`). #' -#' @param dataset Input dataset +#' @param dataset `r roxygen_param_dataset()` #' #' The variables specified by `start_date`, `end_date`, `trt_start_date`, #' `trt_end_date`, `initial_intensity`, and `intensity` are expected. diff --git a/R/derive_vars_aage.R b/R/derive_vars_aage.R index 5c7c5a1233..18ad0c95f8 100644 --- a/R/derive_vars_aage.R +++ b/R/derive_vars_aage.R @@ -6,10 +6,8 @@ #' #' @inheritParams derive_vars_duration #' -#' @param dataset Input dataset -#' -#' The columns specified by the `start_date` and the `end_date` parameter are -#' expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("start_date", "end_date"))` #' #' @param start_date The start date #' @@ -88,7 +86,7 @@ derive_vars_aage <- function(dataset, age_unit = "years", type = "interval") { if (!missing(unit)) { - deprecate_warn("0.12.0", "derive_vars_aage(unit = )", "derive_vars_aage(age_unit = )") + deprecate_stop("0.12.0", "derive_vars_aage(unit = )", "derive_vars_aage(age_unit = )") age_unit <- unit } @@ -120,9 +118,8 @@ derive_vars_aage <- function(dataset, #' units given in the `age_var+U` variable or `age_unit` argument and stores #' in a new variable (`new_var`). #' -#' @param dataset Input dataset. -#' -#' The column specified by the `age_var` argument is expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("age_var"))` #' #' @param age_var Age variable. #' diff --git a/R/derive_vars_dtm_to_dt.R b/R/derive_vars_dtm_to_dt.R index 7b1a74078d..a073a62adf 100644 --- a/R/derive_vars_dtm_to_dt.R +++ b/R/derive_vars_dtm_to_dt.R @@ -2,7 +2,8 @@ #' #' This function creates date(s) as output from datetime variable(s) #' -#' @param dataset Input dataset +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("source_vars"))` #' #' @param source_vars A list of datetime variables created using `exprs()` from #' which dates are to be extracted diff --git a/R/derive_vars_dtm_to_tm.R b/R/derive_vars_dtm_to_tm.R index 9eddb33043..b0fec71e9b 100644 --- a/R/derive_vars_dtm_to_tm.R +++ b/R/derive_vars_dtm_to_tm.R @@ -2,7 +2,8 @@ #' #' This function creates time variable(s) as output from datetime variable(s) #' -#' @param dataset Input dataset +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("source_vars"))` #' #' @param source_vars A list of datetime variables created using `exprs()` from #' which time is to be extracted diff --git a/R/derive_vars_duration.R b/R/derive_vars_duration.R index 2b46e4b6ae..3734b84cd4 100644 --- a/R/derive_vars_duration.R +++ b/R/derive_vars_duration.R @@ -3,10 +3,8 @@ #' Derives duration between two dates, specified by the variables present in #' input dataset e.g., duration of adverse events, relative day, age, ... #' -#' @param dataset Input dataset -#' -#' The variables specified by the `start_date` and the `end_date` parameter are -#' expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("start_date", "end_date"))` #' #' @param new_var Name of variable to create #' diff --git a/R/derive_vars_dy.R b/R/derive_vars_dy.R index e6d2d515f3..82de671881 100644 --- a/R/derive_vars_dy.R +++ b/R/derive_vars_dy.R @@ -3,10 +3,8 @@ #' Adds relative day variables (`--DY`) to the dataset, e.g., `ASTDY` and #' `AENDY`. #' -#' @param dataset Input dataset -#' -#' The columns specified by the `reference_date` and the `source_vars` -#' parameter are expected. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("reference_date", "source_vars"))` #' #' @param reference_date A date or date-time column, e.g., date of first treatment #' or date-time of last exposure to treatment. diff --git a/R/derive_vars_last_dose.R b/R/derive_vars_last_dose.R deleted file mode 100644 index 2164e1b0c5..0000000000 --- a/R/derive_vars_last_dose.R +++ /dev/null @@ -1,96 +0,0 @@ -#' Derive Last Dose -#' -#' Add EX source variables from last dose to the input dataset. -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `derive_vars_joined()` instead. -#' -#' @param dataset Input dataset. -#' The variables specified by the `by_vars` and `analysis_date` parameters are expected. -#' -#' @param dataset_ex Input EX dataset. -#' The variables specified by the `by_vars`, `dose_date`, `new_vars` parameters, -#' and source variables from `traceability_vars` parameter are expected. -#' -#' @param filter_ex Filtering condition applied to EX dataset. -#' For example, it can be used to filter for valid dose. -#' Defaults to NULL. -#' -#' @param by_vars Variables to join by (created by `rlang::exprs`). -#' -#' @param dose_id Variables to identify unique dose (created by `rlang::exprs`). -#' Defaults to empty `exprs()`. -#' -#' @param new_vars Variables to keep from `dataset_ex`, with the option to -#' rename. Can either be variables created by `rlang::exprs` (e.g. -#' `exprs(VISIT)`), or named list returned by [`exprs()`] (e.g. -#' `exprs(LSTEXVIS = VISIT)`). If set to `NULL`, then all variables from -#' `dataset_ex` are kept without renaming. Defaults to `NULL`. -#' -#' @param dose_date The EX dose date variable. A date or date-time object is expected. -#' -#' @param analysis_date The analysis date variable. A date or date-time object is expected. -#' -#' @param single_dose_condition The condition for checking if `dataset_ex` is single dose. An error -#' is issued if the condition is not true. Defaults to `(EXDOSFRQ == "ONCE")`. -#' -#' @param traceability_vars A named list returned by [`exprs()`] listing the traceability variables, -#' e.g. `exprs(LDOSEDOM = "EX", LDOSESEQ = EXSEQ)`. -#' The left-hand side (names of the list elements) gives the names of the traceability variables -#' in the returned dataset. -#' The right-hand side (values of the list elements) gives the values of the traceability variables -#' in the returned dataset. -#' These can be either strings or symbols referring to existing variables. -#' -#' @details -#' When doing date comparison to identify last dose, date-time imputations are done as follows: -#' * `dose_date`: time is imputed to `00:00:00` if the variable is a date variable -#' * `analysis_date`: time is imputed to `23:59:59` if the variable is a date variable -#' -#' The last dose records are identified as follows: -#' -#' 1. The `dataset_ex` is filtered using `filter_ex`, if provided. -#' This is useful for, for example, filtering for valid dose only. -#' 2. The datasets `dataset` and `dataset_ex` are joined using `by_vars`. -#' 3. The last dose is identified: -#' the last dose is the EX record with maximum date where `dose_date` is lower to or equal to -#' `analysis_date`, subject to both date values are non-NA. -#' The last dose is identified per `by_vars`. -#' If multiple EX records exist for the same `dose_date`, then either `dose_id` -#' needs to be supplied (e.g. `dose_id = exprs(EXSEQ)`) to identify unique records, -#' or an error is issued. When `dose_id` is supplied, the last EX record from the same `dose_date` -#' sorted by `dose_id` will be used to identify last dose. -#' 4. The EX source variables (as specified in `new_vars`) from last dose are appended to the -#' `dataset` and returned to the user. -#' -#' This function only works correctly for EX dataset with a structure of single dose per row. -#' If your study EX dataset has multiple doses per row, use [`create_single_dose_dataset()`] to -#' transform the EX dataset into single dose per row structure before calling -#' `derive_vars_last_dose()`. -#' -#' If variables (other than those specified in `by_vars`) exist in both `dataset` and `dataset_ex`, -#' then join cannot be performed properly and an error is issued. To resolve the error, use -#' `new_vars` to either keep variables unique to `dataset_ex`, or use this option to rename -#' variables from `dataset_ex` (e.g. `new_vars = exprs(LSTEXVIS = VISIT)`). -#' -#' @return Input dataset with EX source variables from last dose added. -#' -#' -#' @family deprecated -#' @keywords deprecated -#' -#' @export -derive_vars_last_dose <- function(dataset, - dataset_ex, - filter_ex = NULL, - by_vars = exprs(STUDYID, USUBJID), - dose_id = exprs(), - dose_date, - analysis_date, - single_dose_condition = EXDOSFRQ == "ONCE", - new_vars = NULL, - traceability_vars = NULL) { - deprecate_stop("0.11.0", "derive_vars_last_dose()", "derive_vars_joined()") -} diff --git a/R/derive_vars_query.R b/R/derive_vars_query.R index 6604ccf9bd..ca9025f8d3 100644 --- a/R/derive_vars_query.R +++ b/R/derive_vars_query.R @@ -26,7 +26,7 @@ #' `GRPID`, `SCOPE`, and `SCOPEN` respectively, #' whenever not missing. #' -#' @param dataset Input dataset. +#' @param dataset `r roxygen_param_dataset()` #' #' @param dataset_queries A dataset containing required columns `PREFIX`, #' `GRPNAME`, `SRCVAR`, `TERMNAME`, `TERMID`, and optional columns diff --git a/R/derive_vars_transposed.R b/R/derive_vars_transposed.R index 1ae95521b7..d91e32d2cf 100644 --- a/R/derive_vars_transposed.R +++ b/R/derive_vars_transposed.R @@ -2,9 +2,8 @@ #' #' Adds variables from a vertical dataset after transposing it into a wide one. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` parameter are required +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` #' #' @param dataset_merge Dataset to transpose and merge #' @@ -102,9 +101,8 @@ derive_vars_transposed <- function(dataset, #' #' **Note:** This is a wrapper function for the more generic `derive_vars_transposed()`. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `by_vars` parameter are required +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars"))` #' #' @param dataset_facm FACM dataset #' diff --git a/R/duplicates.R b/R/duplicates.R index b7acb7381e..5a0ca78896 100644 --- a/R/duplicates.R +++ b/R/duplicates.R @@ -35,7 +35,7 @@ get_duplicates_dataset <- function() { #' Extract Duplicate Records #' -#' @param dataset A data frame +#' @param dataset `r roxygen_param_dataset(expected_vars = c("by_vars"))` #' @param by_vars A list of expressions created using `exprs()` identifying #' groups of records in which to look for duplicates #' @@ -78,7 +78,7 @@ extract_duplicate_records <- function(dataset, by_vars) { #' Signal Duplicate Records #' -#' @param dataset A data frame +#' @param dataset `r roxygen_param_dataset(expected_vars = c("by_vars"))` #' @param by_vars A list of expressions created using `exprs()` identifying #' groups of records in which to look for duplicates #' @param msg The condition message diff --git a/R/filter_exist.R b/R/filter_exist.R index b842b02a2a..17de6f306e 100644 --- a/R/filter_exist.R +++ b/R/filter_exist.R @@ -5,9 +5,7 @@ #' this could be used to return ADSL records for subjects that experienced a certain #' adverse event during the course of the study (as per records in ADAE). #' -#' @param dataset Input dataset -#' -#' The variables specified in the `by_vars` parameter are expected in this dataset. +#' @param dataset `r roxygen_param_dataset(expected_vars = c("by_vars"))` #' #' @param dataset_add Source dataset #' diff --git a/R/filter_extreme.R b/R/filter_extreme.R index 8dab991b4f..c08a60646e 100644 --- a/R/filter_extreme.R +++ b/R/filter_extreme.R @@ -2,10 +2,7 @@ #' #' Filters the first or last observation for each by group. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `order` and the `by_vars` parameter are -#' expected. +#' @param dataset `r roxygen_param_dataset(expected_vars = c("by_vars", "order"))` #' #' @param by_vars Grouping variables #' diff --git a/R/filter_joined.R b/R/filter_joined.R index 1d85e6cfdb..d39e4d1ceb 100644 --- a/R/filter_joined.R +++ b/R/filter_joined.R @@ -16,10 +16,7 @@ #' response value can be confirmed by a subsequent assessment. This is commonly #' used in endpoints such as best overall response. #' -#' @param dataset Input dataset -#' -#' The variables specified for `by_vars`, `join_vars`, and `order` are -#' expected. +#' @param dataset `r roxygen_param_dataset(expected_vars = c("by_vars", "order", "join_vars"))` #' #' @param by_vars By variables #' diff --git a/R/filter_relative.R b/R/filter_relative.R index 34c57d796b..aa38420db8 100644 --- a/R/filter_relative.R +++ b/R/filter_relative.R @@ -5,10 +5,7 @@ #' called to select for each subject all observations before the first disease #' progression. #' -#' @param dataset Input dataset -#' -#' The variables specified by the `order` and the `by_vars` parameter are -#' expected. +#' @param dataset `r roxygen_param_dataset(expected_vars = c("by_vars", "order"))` #' #' @param by_vars Grouping variables #' diff --git a/R/get_summary_records.R b/R/get_summary_records.R index 52406841a8..c911a4afe7 100644 --- a/R/get_summary_records.R +++ b/R/get_summary_records.R @@ -11,7 +11,8 @@ #' to the original dataset observations. If you would like to this instead, #' see the `derive_summary_records()` function. #' -#' @param dataset A data frame. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("by_vars", "analysis_var"))` #' #' @param by_vars Variables to consider for generation of groupwise summary #' records. Providing the names of variables in [exprs()] will create a @@ -31,19 +32,35 @@ #' #' @param analysis_var Analysis variable. #' +#' `r lifecycle::badge("deprecated")` Please use `set_values_to` instead. +#' #' @param summary_fun Function that takes as an input the `analysis_var` and #' performs the calculation. +#' +#' `r lifecycle::badge("deprecated")` Please use `set_values_to` instead. +#' #' This can include built-in functions as well as user defined functions, #' for example `mean` or `function(x) mean(x, na.rm = TRUE)`. #' -#' @param set_values_to A list of variable name-value pairs. Use this argument -#' if you need to change the values of any newly derived records. +#' @param set_values_to Variables to be set #' -#' Set a list of variables to some specified value for the new observation(s) +#' The specified variables are set to the specified values for the new +#' observations. +#' +#' Set a list of variables to some specified value for the new records #' + LHS refer to a variable. -#' + RHS refers to the values to set to the variable. This can be a string, a symbol, a numeric -#' value, an expression or NA. -#' (e.g. `exprs(PARAMCD = "TDOSE",PARCAT1 = "OVERALL")`). +#' + RHS refers to the values to set to the variable. This can be a string, a +#' symbol, a numeric value, an expression or NA. If summary functions are +#' used, the values are summarized by the variables specified for `by_vars`. +#' +#' For example: +#' ``` +#' set_values_to = exprs( +#' AVAL = sum(AVAL), +#' PARAMCD = "TDOSE", +#' PARCAT1 = "OVERALL" +#' ) +#' ``` #' #' @return A data frame of derived records. #' @@ -51,88 +68,74 @@ #' #' @keywords der_gen #' -#' @seealso `derive_summary_records()` +#' @seealso [derive_summary_records()], [derive_var_merged_summary()] #' #' @export #' #' @examples #' library(tibble) -#' library(dplyr, warn.conflicts = FALSE) #' #' adeg <- tribble( -#' ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, -#' "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, "", -#' "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, "", -#' "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, "", -#' "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:45", 384, "Placebo", -#' "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", -#' "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", -#' "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:45", 385, "Placebo", -#' "XYZ-1001", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", -#' "XYZ-1001", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", -#' "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, "", -#' "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, "", -#' "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, "", -#' "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:50", 401, "Active 20mg", -#' "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", -#' "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", -#' "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:50", 412, "Active 20mg", -#' "XYZ-1002", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", -#' "XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg", +#' ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, +#' "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_, +#' "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, NA_character_, +#' "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, NA_character_, +#' "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:45", 384, "Placebo", +#' "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", +#' "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", +#' "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:45", 385, "Placebo", +#' "XYZ-1001", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", +#' "XYZ-1001", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", +#' "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, NA_character_, +#' "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, NA_character_, +#' "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, NA_character_, +#' "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:50", 401, "Active 20mg", +#' "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", +#' "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", +#' "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:50", 412, "Active 20mg", +#' "XYZ-1002", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", +#' "XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg" #' ) #' #' # Summarize the average of the triplicate ECG interval values (AVAL) #' get_summary_records( #' adeg, #' by_vars = exprs(USUBJID, PARAM, AVISIT), -#' analysis_var = AVAL, -#' summary_fun = function(x) mean(x, na.rm = TRUE), -#' set_values_to = exprs(DTYPE = "AVERAGE") -#' ) -#' -#' advs <- tribble( -#' ~USUBJID, ~VSSEQ, ~PARAM, ~AVAL, ~VSSTRESU, ~VISIT, ~VSDTC, -#' "XYZ-001-001", 1164, "Weight", 99, "kg", "Screening", "2018-03-19", -#' "XYZ-001-001", 1165, "Weight", 101, "kg", "Run-In", "2018-03-26", -#' "XYZ-001-001", 1166, "Weight", 100, "kg", "Baseline", "2018-04-16", -#' "XYZ-001-001", 1167, "Weight", 94, "kg", "Week 24", "2018-09-30", -#' "XYZ-001-001", 1168, "Weight", 92, "kg", "Week 48", "2019-03-17", -#' "XYZ-001-001", 1169, "Weight", 95, "kg", "Week 52", "2019-04-14", +#' set_values_to = exprs( +#' AVAL = mean(AVAL, na.rm = TRUE), +#' DTYPE = "AVERAGE" +#' ) #' ) #' -#' # Set new values to any variable. Here, `DTYPE = MAXIMUM` refers to `max()` records -#' # and `DTYPE = AVERAGE` refers to `mean()` records. +#' # Derive more than one summary variable #' get_summary_records( -#' advs, -#' by_vars = exprs(USUBJID, PARAM), -#' analysis_var = AVAL, -#' summary_fun = max, -#' set_values_to = exprs(DTYPE = "MAXIMUM") -#' ) %>% -#' get_summary_records( -#' by_vars = exprs(USUBJID, PARAM), -#' analysis_var = AVAL, -#' summary_fun = mean, -#' set_values_to = exprs(DTYPE = "AVERAGE") +#' adeg, +#' by_vars = exprs(USUBJID, PARAM, AVISIT), +#' set_values_to = exprs( +#' AVAL = mean(AVAL), +#' ASTDTM = min(convert_dtc_to_dtm(EGDTC)), +#' AENDTM = max(convert_dtc_to_dtm(EGDTC)), +#' DTYPE = "AVERAGE" #' ) +#' ) #' #' # Sample ADEG dataset with triplicate record for only AVISIT = 'Baseline' #' adeg <- tribble( -#' ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, -#' "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, "", -#' "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, "", -#' "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, "", -#' "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", -#' "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", -#' "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", -#' "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", -#' "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, "", -#' "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, "", -#' "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, "", -#' "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", -#' "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", -#' "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", -#' "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg", +#' ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, +#' "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_, +#' "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, NA_character_, +#' "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, NA_character_, +#' "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", +#' "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", +#' "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", +#' "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", +#' "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, NA_character_, +#' "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, NA_character_, +#' "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, NA_character_, +#' "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", +#' "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", +#' "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", +#' "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg" #' ) #' #' # Compute the average of AVAL only if there are more than 2 records within the @@ -141,32 +144,40 @@ #' adeg, #' by_vars = exprs(USUBJID, PARAM, AVISIT), #' filter = n() > 2, -#' analysis_var = AVAL, -#' summary_fun = function(x) mean(x, na.rm = TRUE), -#' set_values_to = exprs(DTYPE = "AVERAGE") +#' set_values_to = exprs( +#' AVAL = mean(AVAL, na.rm = TRUE), +#' DTYPE = "AVERAGE" +#' ) #' ) get_summary_records <- function(dataset, by_vars, filter = NULL, analysis_var, summary_fun, - set_values_to = NULL) { + set_values_to) { assert_vars(by_vars) - analysis_var <- assert_symbol(enexpr(analysis_var)) filter <- assert_filter_cond(enexpr(filter), optional = TRUE) - assert_s3_class(summary_fun, "function") assert_data_frame( dataset, - required_vars = expr_c(by_vars, analysis_var), + required_vars = by_vars, check_is_grouped = FALSE ) - assert_varval_list(set_values_to, optional = TRUE) + assert_varval_list(set_values_to) + if (!missing(analysis_var) || !missing(summary_fun)) { + deprecate_warn( + "1.0.0", + I("get_summary_records(anaylsis_var = , summary_fun = )"), + "get_summary_records(set_values_to = )" + ) + analysis_var <- assert_symbol(enexpr(analysis_var)) + assert_s3_class(summary_fun, "function") + set_values_to <- exprs(!!analysis_var := {{ summary_fun }}(!!analysis_var), !!!set_values_to) + } # Summarise the analysis value dataset %>% group_by(!!!by_vars) %>% filter_if(filter) %>% - summarise(!!analysis_var := summary_fun(!!analysis_var)) %>% - ungroup() %>% - process_set_values_to(set_values_to) + summarise(!!!set_values_to) %>% + ungroup() } diff --git a/R/globals.R b/R/globals.R index d1e24ad67a..7a4855e8d2 100644 --- a/R/globals.R +++ b/R/globals.R @@ -104,7 +104,6 @@ globalVariables(c( "temp_DT", "temp_from_var", "temp_to_var", - "temp_match_flag", "temp_dose_freq", "temp_new_dose_no", "temp_num_of_doses", diff --git a/R/period_dataset.R b/R/period_dataset.R index f16998e8ab..a57b330cf1 100644 --- a/R/period_dataset.R +++ b/R/period_dataset.R @@ -6,11 +6,10 @@ #' `APERIOD`, `APERSDT`, `APEREDT`, `TRTA`, `APHASEN`, `PHSDTM`, `PHEDTM`, ... #' in OCCDS and BDS datasets. #' -#' @param dataset ADSL dataset -#' -#' The variables specified by `new_vars` and `subject_keys` are expected. For -#' each element of `new_vars` at least one variable of the form of the right -#' hand side value must be available in the dataset. +#' @param dataset +#' `r roxygen_param_dataset(expected_vars = c("new_vars", "subject_keys"))` +#' For each element of `new_vars` at least one variable of the form of the right +#' hand side value must be available in the dataset. #' #' @param new_vars New variables #' @@ -232,9 +231,7 @@ create_period_dataset <- function(dataset, #' reference dataset which has one observations per patient and subperiod, #' period, or phase. #' -#' @param dataset ADSL dataset -#' -#' The variables specified by `subject_keys` are expected. +#' @param dataset `r roxygen_param_dataset(expected_vars = c("subject_keys"))` #' #' @param dataset_ref Period reference dataset #' diff --git a/R/restrict_derivation.R b/R/restrict_derivation.R index 7a5605e7b4..c130e71a5d 100644 --- a/R/restrict_derivation.R +++ b/R/restrict_derivation.R @@ -2,7 +2,7 @@ #' #' Execute a derivation on a subset of the input dataset. #' -#' @param dataset Input dataset +#' @param dataset `r roxygen_param_dataset()` #' #' @param derivation Derivation #' @@ -12,9 +12,6 @@ #' The function must provide the `dataset` argument and all arguments #' specified in the `params()` objects passed to the `arg` argument. #' -#' Please note that it is not possible to specify `{dplyr}` -#' functions like `mutate()` or `summarize()`. -#' #' @param args Arguments of the derivation #' #' A `params()` object is expected. @@ -78,11 +75,8 @@ restrict_derivation <- function(dataset, filter) { # Check input assert_data_frame(dataset) - assert_function(derivation, params = c("dataset")) assert_s3_class(args, "params", optional = TRUE) - if (!is.null(args)) { - assert_function(derivation, names(args)) - } + assert_function(derivation, names(args)) filter <- assert_filter_cond(enexpr(filter)) # Split input dataset diff --git a/R/roxygen2.R b/R/roxygen2.R new file mode 100644 index 0000000000..f37a44b158 --- /dev/null +++ b/R/roxygen2.R @@ -0,0 +1,16 @@ +# THIS FILE INCLUDES FUNCTION THAT ARE RE-USED THROUGHOUT +# roxygen2 COMMENTS TO GENERATE DOCUMENTATION TEXT + +roxygen_param_dataset <- function(expected_vars = NULL) { + if (is.null(expected_vars)) { + dataset_text <- "Input dataset" + } else { + dataset_text <- paste0( + "Input dataset \n \n", + "The variables specified by the ", + enumerate(expected_vars), + " argument(s) to be expected." + ) + } + return(dataset_text) +} diff --git a/R/slice_derivation.R b/R/slice_derivation.R index 2a4eb39056..c0c4a94ab7 100644 --- a/R/slice_derivation.R +++ b/R/slice_derivation.R @@ -4,7 +4,7 @@ #' derivation is called separately. Some or all arguments of the derivation #' may vary depending on the slice. #' -#' @param dataset Input dataset +#' @param dataset `r roxygen_param_dataset()` #' #' @param derivation Derivation #' diff --git a/README.md b/README.md index c7d45b2aa4..c5247888e4 100644 --- a/README.md +++ b/README.md @@ -17,28 +17,27 @@ to develop ADaM datasets in R. ## Installation -The package is available from CRAN and can be installed by running `install.packages("admiral")`. - -To install the latest development version of the package directly from GitHub use the following code: +The package is available from CRAN and can be installed with ```r -if (!requireNamespace("remotes", quietly = TRUE)) { - install.packages("remotes") -} +install.packages("admiral") +``` + +To install the development version of the package from GitHub run -remotes::install_github("pharmaverse/pharmaversesdtm") # This is a required dependency of {admiral} -remotes::install_github("pharmaverse/admiraldev") # This is a required dependency of {admiral} -remotes::install_github("pharmaverse/admiral") +```r +# install.packages("devtools") +devtools::install_github("pharmaverse/admiral") ``` ## Release Schedule -[{admiral}](https://pharmaverse.github.io/admiral/cran-release/) releases are targeted for the first Monday of the last month of each quarter. Pull Requests will be frozen the week before a release. +[{admiral}](https://pharmaverse.github.io/admiral/cran-release/) releases are targeted for the first Monday of the last month of each quarter. The {admiral} family has several downstream and upstream dependencies and so this release shall be done in three Phases: -* Phase 1 release is for [{admiraldev}](https://pharmaverse.github.io/admiraldev/main/), [{pharmaversesdtm}](https://pharmaverse.github.io/pharmaversesdtm/main/), and [{admiral}](https://pharmaverse.github.io/admiral/cran-release/) core -* Phase 2 release is extension packages, e.g. [{admiralonco}](https://pharmaverse.github.io/admiralonco/main/), [{admiralophtha}](https://pharmaverse.github.io/admiralophtha/main/), [{admiralvaccine}](https://pharmaverse.github.io/admiralvaccine/main/) +* Phase 1 release is for [{admiraldev}](https://pharmaverse.github.io/admiraldev/), [{pharmaversesdtm}](https://pharmaverse.github.io/pharmaversesdtm/), and [{admiral}](https://pharmaverse.github.io/admiral/) core +* Phase 2 release is extension packages, e.g. [{admiralonco}](https://pharmaverse.github.io/admiralonco/), [{admiralophtha}](https://pharmaverse.github.io/admiralophtha/), [{admiralvaccine}](https://pharmaverse.github.io/admiralvaccine/) | Release Schedule | Phase 1- Date and Packages | Phase 2- Date and Packages | | ---------------- | ------------------------------------------------------------------------ | -------------------------------------------------------------------- | @@ -78,15 +77,29 @@ We will provide: * Vignettes on how to create ADSL, BDS and OCCDS datasets, including example scripts * Vignettes for ADaM dataset specific functionality (i.e. dictionary coding, date imputation, SMQs ...) -## Types of Packages +## The {admiral} Family of Packages -There will be 3 foreseeable types of `{admiral}` packages: +There are three types of packages in the `{admiral}` family: * Core package---one package containing all core functions required to create ADaMs, usable by any company (i.e. general derivations, utility functions and checks for ADSL, OCCDS and BDS) * TA (Therapeutic Area) package extensions---one package per TA with functions that are specific to algorithms and requirements for that particular TA (e.g. [`{admiralonco}`](https://pharmaverse.github.io/admiralonco/)) * Company package extensions---specific needs and plug-ins for the company, such as access to metadata (e.g. `{admiralroche}` or `{admiralgsk}`) + +## Related Packages + +Related data packages include: + +* [{pharmaversesdtm}](https://pharmaverse.github.io/pharmaversesdtm/main/)---this contains test SDTM data sourced from the [CDISC pilot project](https://github.com/cdisc-org/sdtm-adam-pilot-project) or constructed ad-hoc by the `{admiral}` team. This is a prerequisite package for `{admiral}`. +* [{pharmaverseadam}](https://pharmaverse.github.io/pharmaverseadam/main/)---this contains test ADaM data automatically generated by running the ADaM `{admiral}` and TA package extensions templates on the [{pharmaversesdtm}](https://pharmaverse.github.io/pharmaversesdtm/main/) data. + +Both these packages are developed by the `{admiral}` team, but can used across the pharmaverse as common, open-source test SDTM or ADaM data. + +The following packages are also useful when working with ADaM datasets: + +* [{metacore}](https://atorus-research.github.io/metacore/) and [{metatools}](https://pharmaverse.github.io/metatools/)---these enable users to manipulate and work with dataset metadata. +* [{xportr}](https://atorus-research.github.io/xportr/)---this provides functionality to get xpt files ready for transport. ## Admiral Manifesto diff --git a/_pkgdown.yml b/_pkgdown.yml index 8c52c88221..bc8581f9fd 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -15,6 +15,9 @@ repo: news: cran_dates: true +development: + mode: auto + authors: before: "We define *authors* as those who are actively maintaining the code base, and *contributors* as those who made a significant contribution in the past. For all acknowledgements, see the eponymous section in the [Home Page](https://pharmaverse.github.io/admiral/cran-release/)." footer: diff --git a/inst/WORDLIST b/inst/WORDLIST index c8b09c2850..67c22fc965 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -317,6 +317,7 @@ onwards parttime pharmaverse pharmaversesdtm +pharmaverseadam phosphatase poppk pre diff --git a/inst/templates/ad_adeg.R b/inst/templates/ad_adeg.R index 62a680a7da..a7e4d5d7b8 100644 --- a/inst/templates/ad_adeg.R +++ b/inst/templates/ad_adeg.R @@ -198,10 +198,11 @@ adeg <- adeg %>% adeg <- adeg %>% derive_summary_records( by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, PARAMCD, AVISITN, AVISIT, ADT), - analysis_var = AVAL, - summary_fun = function(x) mean(x, na.rm = TRUE), filter = dplyr::n() >= 2 & PARAMCD != "EGINTP", - set_values_to = exprs(DTYPE = "AVERAGE") + set_values_to = exprs( + AVAL = mean(AVAL, na.rm = TRUE), + DTYPE = "AVERAGE" + ) ) adeg <- adeg %>% diff --git a/inst/templates/ad_advs.R b/inst/templates/ad_advs.R index 1e43d8391d..fd630e2c47 100644 --- a/inst/templates/ad_advs.R +++ b/inst/templates/ad_advs.R @@ -158,9 +158,10 @@ advs <- advs %>% derive_summary_records( by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, PARAMCD, AVISITN, AVISIT, ADT, ADY), filter = !is.na(AVAL), - analysis_var = AVAL, - summary_fun = mean, - set_values_to = exprs(DTYPE = "AVERAGE") + set_values_to = exprs( + AVAL = mean(AVAL), + DTYPE = "AVERAGE" + ) ) advs <- advs %>% diff --git a/man/call_derivation.Rd b/man/call_derivation.Rd index 313cef60c5..79c795f5e9 100644 --- a/man/call_derivation.Rd +++ b/man/call_derivation.Rd @@ -7,7 +7,7 @@ call_derivation(dataset = NULL, derivation, variable_params, ...) } \arguments{ -\item{dataset}{The input dataset} +\item{dataset}{Input dataset} \item{derivation}{The derivation function to call diff --git a/man/create_period_dataset.Rd b/man/create_period_dataset.Rd index 8a6f99bf3f..64086f3002 100644 --- a/man/create_period_dataset.Rd +++ b/man/create_period_dataset.Rd @@ -11,10 +11,10 @@ create_period_dataset( ) } \arguments{ -\item{dataset}{ADSL dataset +\item{dataset}{Input dataset -The variables specified by \code{new_vars} and \code{subject_keys} are expected. For -each element of \code{new_vars} at least one variable of the form of the right +The variables specified by the \code{new_vars} and \code{subject_keys} argument(s) to be expected. +For each element of \code{new_vars} at least one variable of the form of the right hand side value must be available in the dataset.} \item{new_vars}{New variables diff --git a/man/create_single_dose_dataset.Rd b/man/create_single_dose_dataset.Rd index fc4e10c82d..70d314fd0d 100644 --- a/man/create_single_dose_dataset.Rd +++ b/man/create_single_dose_dataset.Rd @@ -21,8 +21,7 @@ create_single_dose_dataset( \arguments{ \item{dataset}{Input dataset -The columns specified by \code{dose_freq}, \code{start_date} and the \code{end_date} -parameters are expected.} +The variables specified by the \code{dose_freq}, \code{start_date} and \code{end_date} argument(s) to be expected.} \item{dose_freq}{The dose frequency diff --git a/man/derive_basetype_records.Rd b/man/derive_basetype_records.Rd index 44b88473c3..1bc0d42fa1 100644 --- a/man/derive_basetype_records.Rd +++ b/man/derive_basetype_records.Rd @@ -9,7 +9,7 @@ derive_basetype_records(dataset, basetypes) \arguments{ \item{dataset}{Input dataset -The columns specified in the expressions inside \code{basetypes} are required.} +The variables specified by the \code{basetypes} argument(s) to be expected.} \item{basetypes}{A \emph{named} list of expressions created using the \code{rlang::exprs()} function diff --git a/man/derive_expected_records.Rd b/man/derive_expected_records.Rd index 146b48ff60..43bbe10b66 100644 --- a/man/derive_expected_records.Rd +++ b/man/derive_expected_records.Rd @@ -15,8 +15,7 @@ derive_expected_records( \arguments{ \item{dataset}{Input dataset -A data frame, the columns from \code{dataset_ref} and specified by the -\code{by_vars} parameter are expected.} +The variables specified by the \code{dataset_ref} and \code{by_vars} argument(s) to be expected.} \item{dataset_expected_obs}{\emph{Deprecated}, please use \code{dataset_ref} instead.} diff --git a/man/derive_extreme_event.Rd b/man/derive_extreme_event.Rd index 21b4e90564..e61c514891 100644 --- a/man/derive_extreme_event.Rd +++ b/man/derive_extreme_event.Rd @@ -20,8 +20,7 @@ derive_extreme_event( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{order} and the \code{by_vars} parameter are -expected.} +The variables specified by the \code{by_vars} and \code{order} argument(s) to be expected.} \item{by_vars}{Grouping variables @@ -85,12 +84,22 @@ by variables and the order. The specified variables are set to the specified values for the new observations. -A list of variable name-value pairs is expected. +Set a list of variables to some specified value for the new records \itemize{ -\item LHS refers to a variable. +\item LHS refer to a variable. \item RHS refers to the values to set to the variable. This can be a string, a -symbol, a numeric value, an expression, or \code{NA}, e.g., \code{exprs(PARAMCD = "TDOSE", PARCAT1 = "OVERALL")}. -}} +symbol, a numeric value, an expression or NA. If summary functions are +used, the values are summarized by the variables specified for \code{by_vars}. +} + +For example: + +\if{html}{\out{
}}\preformatted{ set_values_to = exprs( + AVAL = sum(AVAL), + PARAMCD = "TDOSE", + PARCAT1 = "OVERALL" + ) +}\if{html}{\out{
}}} \item{keep_source_vars}{Variables to keep from the source dataset diff --git a/man/derive_extreme_records.Rd b/man/derive_extreme_records.Rd index 872235d156..a394c9b104 100644 --- a/man/derive_extreme_records.Rd +++ b/man/derive_extreme_records.Rd @@ -15,10 +15,9 @@ derive_extreme_records( check_type = "warning", exist_flag = NULL, true_value = "Y", - false_value = "N", + false_value = NA_character_, keep_source_vars = exprs(everything()), - set_values_to, - filter + set_values_to ) } \arguments{ @@ -118,22 +117,22 @@ automatically.} The specified variables are set to the specified values for the new observations. -A list of variable name-value pairs is expected. +Set a list of variables to some specified value for the new records \itemize{ -\item LHS refers to a variable. +\item LHS refer to a variable. \item RHS refers to the values to set to the variable. This can be a string, a -symbol, a numeric value, an expression, or \code{NA}, e.g., \code{exprs(PARAMCD = "TDOSE", PARCAT1 = "OVERALL")}. -}} - -\item{filter}{Filter for observations to consider - -\emph{Deprecated}, please use the above \code{filter_add} argument instead. +symbol, a numeric value, an expression or NA. If summary functions are +used, the values are summarized by the variables specified for \code{by_vars}. +} -Only observations fulfilling the specified condition are taken into account -for selecting the first or last observation. If the argument is not -specified, all observations are considered. +For example: -\emph{Permitted Values}: a condition} +\if{html}{\out{
}}\preformatted{ set_values_to = exprs( + AVAL = sum(AVAL), + PARAMCD = "TDOSE", + PARCAT1 = "OVERALL" + ) +}\if{html}{\out{
}}} } \value{ The input dataset with the first or last observation of each by group diff --git a/man/derive_locf_records.Rd b/man/derive_locf_records.Rd index 5f500aaf0b..dc8cb92d95 100644 --- a/man/derive_locf_records.Rd +++ b/man/derive_locf_records.Rd @@ -17,8 +17,7 @@ derive_locf_records( \arguments{ \item{dataset}{Input dataset -The columns specified by the \code{by_vars}, \code{analysis_var}, \code{order}, -\code{keep_vars} parameters are expected.} +The variables specified by the \code{by_vars}, \code{analysis_var}, \code{order} and \code{keep_vars} argument(s) to be expected.} \item{dataset_expected_obs}{\emph{Deprecated}, please use \code{dataset_ref} instead.} diff --git a/man/derive_param_bmi.Rd b/man/derive_param_bmi.Rd index 5674f1007c..ecca7410dc 100644 --- a/man/derive_param_bmi.Rd +++ b/man/derive_param_bmi.Rd @@ -18,8 +18,8 @@ derive_param_bmi( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} parameter, \code{PARAMCD}, and -\code{AVAL} are expected. +The variables specified by the \code{by_vars} argument(s) to be expected. +\code{PARAMCD}, and \code{AVAL} are expected as well. The variable specified by \code{by_vars} and \code{PARAMCD} must be a unique key of the input dataset after restricting it by the filter condition (\code{filter} diff --git a/man/derive_param_bsa.Rd b/man/derive_param_bsa.Rd index 6295555c54..78a98814e6 100644 --- a/man/derive_param_bsa.Rd +++ b/man/derive_param_bsa.Rd @@ -19,8 +19,8 @@ derive_param_bsa( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} parameter, \code{PARAMCD}, and -\code{AVAL} are expected. +The variables specified by the \code{by_vars} argument(s) to be expected. +\code{PARAMCD}, and \code{AVAL} are expected as well. The variable specified by \code{by_vars} and \code{PARAMCD} must be a unique key of the input dataset after restricting it by the filter condition (\code{filter} diff --git a/man/derive_param_computed.Rd b/man/derive_param_computed.Rd index 12cdf77ec6..88002805cb 100644 --- a/man/derive_param_computed.Rd +++ b/man/derive_param_computed.Rd @@ -21,7 +21,8 @@ derive_param_computed( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} parameter are expected. +The variables specified by the \code{by_vars} argument(s) to be expected. +\code{PARAMCD} is expected as well. The variable specified by \code{by_vars} and \code{PARAMCD} must be a unique key of the input dataset after restricting it by the filter condition (\code{filter} diff --git a/man/derive_param_doseint.Rd b/man/derive_param_doseint.Rd index f67b68afff..877ac7d3ad 100644 --- a/man/derive_param_doseint.Rd +++ b/man/derive_param_doseint.Rd @@ -17,8 +17,8 @@ derive_param_doseint( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} parameter, \code{PARAMCD}, and -\code{AVAL} are expected. +The variables specified by the \code{by_vars} argument(s) to be expected. +\code{PARAMCD}, and \code{AVAL} are expected as well. The variable specified by \code{by_vars} and \code{PARAMCD} must be a unique key of the input dataset after restricting it by the filter condition (\code{filter} diff --git a/man/derive_param_exist_flag.Rd b/man/derive_param_exist_flag.Rd index 6866626294..f56fdbb032 100644 --- a/man/derive_param_exist_flag.Rd +++ b/man/derive_param_exist_flag.Rd @@ -13,18 +13,15 @@ derive_param_exist_flag( false_value = NA_character_, missing_value = NA_character_, filter_add = NULL, - aval_fun, by_vars = get_admiral_option("subject_keys"), - set_values_to, - dataset_adsl, - subject_keys + set_values_to ) } \arguments{ \item{dataset}{Input dataset -The variables specified for \code{by_vars} and the \code{PARAMCD} variable are -expected.} +The variables specified by the \code{by_vars} argument(s) to be expected. +\code{PARAMCD} is expected as well.} \item{dataset_ref}{Reference dataset, e.g., ADSL @@ -91,11 +88,6 @@ considered. \emph{Permitted Values}: a condition} -\item{aval_fun}{Function to map character analysis value (\code{AVALC}) to numeric -analysis value (\code{AVAL}) - -\emph{Deprecated}, please use \code{set_values_to} instead.} - \item{by_vars}{Variables to uniquely identify a group A list of symbols created using \code{exprs()} is expected.} @@ -105,10 +97,6 @@ A list of symbols created using \code{exprs()} is expected.} A named list returned by \code{exprs()} defining the variables to be set for the new parameter, e.g. \code{exprs(PARAMCD = "MDIS", PARAM = "Measurable Disease at Baseline")} is expected. The values must be symbols, character strings, numeric values, \code{NA}, or expressions.} - -\item{dataset_adsl}{\emph{Deprecated}, please use \code{dataset_ref} instead.} - -\item{subject_keys}{\emph{Deprecated}, please use \code{by_vars} instead.} } \value{ The input dataset with a new parameter indicating if an event diff --git a/man/derive_param_exposure.Rd b/man/derive_param_exposure.Rd index 5f0d4fd0be..c946090150 100644 --- a/man/derive_param_exposure.Rd +++ b/man/derive_param_exposure.Rd @@ -16,9 +16,10 @@ derive_param_exposure( } \arguments{ \item{dataset}{Input dataset + +The variables specified by the \code{by_vars} and \code{analysis_var} argument(s) to be expected. +\code{PARAMCD} is expected as well, \itemize{ -\item The variables specified by the \code{by_vars},\code{analysis_var} parameters and \code{PARAMCD} are -expected, \item Either \code{ASTDTM} and \code{AENDTM} or \code{ASTDT} and \code{AENDT} are also expected. }} diff --git a/man/derive_param_extreme_event.Rd b/man/derive_param_extreme_event.Rd deleted file mode 100644 index c869f5e47f..0000000000 --- a/man/derive_param_extreme_event.Rd +++ /dev/null @@ -1,145 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_param_extreme_event.R -\name{derive_param_extreme_event} -\alias{derive_param_extreme_event} -\title{Add an Extreme Event Parameter} -\usage{ -derive_param_extreme_event( - dataset = NULL, - dataset_adsl, - dataset_source, - filter_source, - order = NULL, - new_var = NULL, - true_value = "Y", - false_value = "N", - mode = "first", - subject_keys = get_admiral_option("subject_keys"), - set_values_to, - check_type = "warning" -) -} -\arguments{ -\item{dataset}{Input dataset - -The \code{PARAMCD} variable is expected.} - -\item{dataset_adsl}{ADSL input dataset - -The variables specified for \code{subject_keys} are expected. For each -observation of the specified dataset a new observation is added to the -input dataset.} - -\item{dataset_source}{Source dataset - -All observations in the specified dataset fulfilling the condition -specified by \code{filter_source} are considered as an event. - -The variables specified by the \code{subject_keys} and -\code{order} argument (if applicable) are expected.} - -\item{filter_source}{Source filter - -All observations in \code{dataset_source} fulfilling the specified condition are -considered as an event. - -For subjects with at least one event \code{new_var} is set to \code{true_value}. - -For all other subjects \code{new_var} is set to \code{false_value}.} - -\item{order}{Order variable - -List of symbols for sorting the source dataset (\code{dataset_source}). - -\emph{Permitted Values}: list of expressions created by \code{exprs()}, e.g., -\code{exprs(ADT, desc(AVAL))}.} - -\item{new_var}{New variable - -The name of the variable which will indicate whether an event happened or not.} - -\item{true_value}{True value - -For all subjects with at least one observation in the source dataset -(\code{dataset_source}) fulfilling the event condition (\code{filter_source}), -\code{new_var} is set to the specified value \code{true_value}.} - -\item{false_value}{False value - -For all other subjects in \code{dataset_adsl} without an event, \code{new_var} is set to -the specified value \code{false_value}.} - -\item{mode}{Selection mode (first or last) - -If \code{"first"} is specified, the first observation of each subject is selected. -If \code{"last"} is specified, the last observation of each subject is selected. - -\emph{Permitted Values}: \code{"first"}, \code{"last"}} - -\item{subject_keys}{Variables to uniquely identify a subject - -A list of symbols created using \code{exprs()} is expected.} - -\item{set_values_to}{Variables to set - -A named list returned by \code{exprs()} defining the variables to be set for the -new parameter, e.g. \code{exprs(PARAMCD = "PD", PARAM = "Disease Progression")} -is expected. The values must be symbols, character strings, numeric values, -\code{NA}, or an expression. Note, if you require a date or datetime variable to -be populated, this needs to be defined here.} - -\item{check_type}{Check uniqueness? - -If \code{"warning"} or \code{"error"} is specified, a message is issued if the -observations of the source dataset (\code{dataset_source}) restricted by -\code{filter_source} are not unique with respect to the subject keys -(\code{subject_key} argument) and \code{order}. - -\emph{Permitted Values}: \code{"none"}, \code{"warning"}, \code{"error"}} -} -\value{ -The input dataset with a new parameter indicating if and when an -event occurred -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{derive_extreme_records()} instead. - -Add a new parameter for the first or last event occurring in a dataset. The -variable given in \code{new_var} indicates if an event occurred or not. For -example, the function can derive a parameter for the first disease -progression. -} -\details{ -\enumerate{ -\item The source dataset (\code{dataset_source}) is restricted to observations fulfilling -\code{filter_source}. -\item For each subject (with respect to the variables specified for the -\code{subject_keys} argument) either the first or last observation from the restricted -source dataset is selected. This is depending on \code{mode}, (with respect to \code{order}, -if applicable) where the event condition (\code{filter_source} argument) is fulfilled. -\item For each observation in \code{dataset_adsl} a new observation is created. For -subjects with event \code{new_var} is set to \code{true_value}. For all other -subjects \code{new_var} is set to \code{false_value}. -For subjects with event all variables from \code{dataset_source} are kept. For -subjects without event all variables which are in both \code{dataset_adsl} and -\code{dataset_source} are kept. -\item The variables specified by the \code{set_values_to} argument are added to -the new observations. -\item The new observations are added to input dataset. -} -} -\seealso{ -Other deprecated: -\code{\link{derive_var_basetype}()}, -\code{\link{derive_var_confirmation_flag}()}, -\code{\link{derive_var_last_dose_amt}()}, -\code{\link{derive_var_last_dose_date}()}, -\code{\link{derive_var_last_dose_grp}()}, -\code{\link{derive_var_merged_cat}()}, -\code{\link{derive_var_merged_character}()}, -\code{\link{derive_vars_last_dose}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/derive_param_framingham.Rd b/man/derive_param_framingham.Rd index 26a89ff1f7..8aec00eec6 100644 --- a/man/derive_param_framingham.Rd +++ b/man/derive_param_framingham.Rd @@ -24,8 +24,8 @@ derive_param_framingham( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} parameter, \code{PARAMCD}, and -\code{AVAL} are expected. +The variables specified by the \code{by_vars} argument(s) to be expected. +\code{PARAMCD}, and \code{AVAL} are expected as well. The variable specified by \code{by_vars} and \code{PARAMCD} must be a unique key of the input dataset after restricting it by the filter condition (\code{filter} diff --git a/man/derive_param_map.Rd b/man/derive_param_map.Rd index 93b412d356..472e26bd56 100644 --- a/man/derive_param_map.Rd +++ b/man/derive_param_map.Rd @@ -18,8 +18,8 @@ derive_param_map( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} parameter, \code{PARAMCD}, and -\code{AVAL} are expected. +The variables specified by the \code{by_vars} argument(s) to be expected. +\code{PARAMCD}, and \code{AVAL} are expected as well. The variable specified by \code{by_vars} and \code{PARAMCD} must be a unique key of the input dataset after restricting it by the filter condition (\code{filter} diff --git a/man/derive_param_qtc.Rd b/man/derive_param_qtc.Rd index 512945e8b0..594b7b1cd3 100644 --- a/man/derive_param_qtc.Rd +++ b/man/derive_param_qtc.Rd @@ -18,8 +18,8 @@ derive_param_qtc( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} and the \code{unit_var} parameter, -\code{PARAMCD}, and \code{AVAL} are expected. +The variables specified by the \code{by_vars} and \code{get_unit_expr} argument(s) to be expected. +\code{PARAMCD}, and \code{AVAL} are expected as well. The variable specified by \code{by_vars} and \code{PARAMCD} must be a unique key of the input dataset after restricting it by the filter condition (\code{filter} diff --git a/man/derive_param_rr.Rd b/man/derive_param_rr.Rd index f6ba8b9add..ddf944a837 100644 --- a/man/derive_param_rr.Rd +++ b/man/derive_param_rr.Rd @@ -16,8 +16,8 @@ derive_param_rr( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} parameter, \code{PARAMCD}, and \code{AVAL} -are expected. +The variables specified by the \code{by_vars} argument(s) to be expected. +\code{PARAMCD}, and \code{AVAL} are expected as well. The variable specified by \code{by_vars} and \code{PARAMCD} must be a unique key of the input dataset after restricting it by the filter condition (\code{filter} diff --git a/man/derive_param_tte.Rd b/man/derive_param_tte.Rd index 4177cbf61f..dc17c2b7f7 100644 --- a/man/derive_param_tte.Rd +++ b/man/derive_param_tte.Rd @@ -19,8 +19,7 @@ derive_param_tte( } \arguments{ \item{dataset}{Input dataset - -The \code{PARAMCD} variable is expected.} +\code{PARAMCD} is expected.} \item{dataset_adsl}{ADSL input dataset diff --git a/man/derive_param_wbc_abs.Rd b/man/derive_param_wbc_abs.Rd index e2278299b9..15c8555dc6 100644 --- a/man/derive_param_wbc_abs.Rd +++ b/man/derive_param_wbc_abs.Rd @@ -18,8 +18,8 @@ derive_param_wbc_abs( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} argument, \code{PARAMCD}, and \code{AVAL} -are expected to be present. +The variables specified by the \code{by_vars} argument(s) to be expected. +\code{PARAMCD}, and \code{AVAL} are expected as well. The variable specified by \code{by_vars} and \code{PARAMCD} must be a unique key of the input dataset, and to the parameters specified by \code{wbc_code} and \code{diff_code}.} diff --git a/man/derive_summary_records.Rd b/man/derive_summary_records.Rd index 05281d4767..eba2324687 100644 --- a/man/derive_summary_records.Rd +++ b/man/derive_summary_records.Rd @@ -10,11 +10,13 @@ derive_summary_records( filter = NULL, analysis_var, summary_fun, - set_values_to = NULL + set_values_to ) } \arguments{ -\item{dataset}{A data frame.} +\item{dataset}{Input dataset + +The variables specified by the \code{by_vars} and \code{analysis_var} argument(s) to be expected.} \item{by_vars}{Variables to consider for generation of groupwise summary records. Providing the names of variables in \code{\link[=exprs]{exprs()}} will create a @@ -33,10 +35,15 @@ values greater than mean of \code{AVAL} with in \code{by_vars}. than 2. }} -\item{analysis_var}{Analysis variable.} +\item{analysis_var}{Analysis variable. + +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{set_values_to} instead.} \item{summary_fun}{Function that takes as an input the \code{analysis_var} and performs the calculation. + +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{set_values_to} instead. + This can include built-in functions as well as user defined functions, for example \code{mean} or \code{function(x) mean(x, na.rm = TRUE)}.} @@ -45,12 +52,22 @@ for example \code{mean} or \code{function(x) mean(x, na.rm = TRUE)}.} The specified variables are set to the specified values for the new observations. -A list of variable name-value pairs is expected. +Set a list of variables to some specified value for the new records \itemize{ -\item LHS refers to a variable. +\item LHS refer to a variable. \item RHS refers to the values to set to the variable. This can be a string, a -symbol, a numeric value, an expression, or \code{NA}, e.g., \code{exprs(PARAMCD = "TDOSE", PARCAT1 = "OVERALL")}. -}} +symbol, a numeric value, an expression or NA. If summary functions are +used, the values are summarized by the variables specified for \code{by_vars}. +} + +For example: + +\if{html}{\out{
}}\preformatted{ set_values_to = exprs( + AVAL = sum(AVAL), + PARAMCD = "TDOSE", + PARCAT1 = "OVERALL" + ) +}\if{html}{\out{
}}} } \value{ A data frame with derived records appended to original dataset. @@ -68,82 +85,74 @@ will be set to \code{NA}. } \examples{ library(tibble) -library(dplyr, warn.conflicts = TRUE) +library(dplyr) adeg <- tribble( - ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, - "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, "", - "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, "", - "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, "", - "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:45", 384, "Placebo", - "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", - "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", - "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:45", 385, "Placebo", - "XYZ-1001", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", - "XYZ-1001", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", - "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, "", - "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, "", - "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, "", - "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:50", 401, "Active 20mg", - "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", - "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", - "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:50", 412, "Active 20mg", - "XYZ-1002", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", - "XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg", -) + ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, + "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_, + "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, NA_character_, + "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, NA_character_, + "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:45", 384, "Placebo", + "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", + "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", + "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:45", 385, "Placebo", + "XYZ-1001", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", + "XYZ-1001", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", + "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, NA_character_, + "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, NA_character_, + "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, NA_character_, + "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:50", 401, "Active 20mg", + "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", + "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", + "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:50", 412, "Active 20mg", + "XYZ-1002", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", + "XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg" +) \%>\% + mutate( + ADTM = convert_dtc_to_dtm(EGDTC) + ) # Summarize the average of the triplicate ECG interval values (AVAL) derive_summary_records( adeg, by_vars = exprs(USUBJID, PARAM, AVISIT), - analysis_var = AVAL, - summary_fun = function(x) mean(x, na.rm = TRUE), - set_values_to = exprs(DTYPE = "AVERAGE") -) - -advs <- tribble( - ~USUBJID, ~VSSEQ, ~PARAM, ~AVAL, ~VSSTRESU, ~VISIT, ~VSDTC, - "XYZ-001-001", 1164, "Weight", 99, "kg", "Screening", "2018-03-19", - "XYZ-001-001", 1165, "Weight", 101, "kg", "Run-In", "2018-03-26", - "XYZ-001-001", 1166, "Weight", 100, "kg", "Baseline", "2018-04-16", - "XYZ-001-001", 1167, "Weight", 94, "kg", "Week 24", "2018-09-30", - "XYZ-001-001", 1168, "Weight", 92, "kg", "Week 48", "2019-03-17", - "XYZ-001-001", 1169, "Weight", 95, "kg", "Week 52", "2019-04-14", -) + set_values_to = exprs( + AVAL = mean(AVAL, na.rm = TRUE), + DTYPE = "AVERAGE" + ) +) \%>\% + arrange(USUBJID, AVISIT) -# Set new values to any variable. Here, `DTYPE = MAXIMUM` refers to `max()` records -# and `DTYPE = AVERAGE` refers to `mean()` records. +# Derive more than one summary variable derive_summary_records( - advs, - by_vars = exprs(USUBJID, PARAM), - analysis_var = AVAL, - summary_fun = max, - set_values_to = exprs(DTYPE = "MAXIMUM") -) \%>\% - derive_summary_records( - by_vars = exprs(USUBJID, PARAM), - analysis_var = AVAL, - summary_fun = mean, - set_values_to = exprs(DTYPE = "AVERAGE") + adeg, + by_vars = exprs(USUBJID, PARAM, AVISIT), + set_values_to = exprs( + AVAL = mean(AVAL), + ADTM = max(ADTM), + DTYPE = "AVERAGE" ) +) \%>\% + arrange(USUBJID, AVISIT) \%>\% + select(-EGSEQ, -TRTA) # Sample ADEG dataset with triplicate record for only AVISIT = 'Baseline' adeg <- tribble( - ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, - "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, "", - "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, "", - "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, "", - "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", - "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", - "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", - "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", - "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, "", - "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, "", - "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, "", - "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", - "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", - "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", - "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg", + ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, + "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_, + "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, NA_character_, + "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, NA_character_, + "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", + "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", + "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", + "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", + "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, NA_character_, + "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, NA_character_, + "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, NA_character_, + "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", + "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", + "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", + "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg" ) # Compute the average of AVAL only if there are more than 2 records within the @@ -152,13 +161,15 @@ derive_summary_records( adeg, by_vars = exprs(USUBJID, PARAM, AVISIT), filter = n() > 2, - analysis_var = AVAL, - summary_fun = function(x) mean(x, na.rm = TRUE), - set_values_to = exprs(DTYPE = "AVERAGE") -) + set_values_to = exprs( + AVAL = mean(AVAL, na.rm = TRUE), + DTYPE = "AVERAGE" + ) +) \%>\% + arrange(USUBJID, AVISIT) } \seealso{ -\code{get_summary_records()} +\code{\link[=get_summary_records]{get_summary_records()}}, \code{\link[=derive_var_merged_summary]{derive_var_merged_summary()}} BDS-Findings Functions for adding Parameters/Records: \code{\link{default_qtc_paramcd}()}, diff --git a/man/derive_var_age_years.Rd b/man/derive_var_age_years.Rd index cee141541c..2f0361f722 100644 --- a/man/derive_var_age_years.Rd +++ b/man/derive_var_age_years.Rd @@ -7,9 +7,9 @@ derive_var_age_years(dataset, age_var, age_unit = NULL, new_var) } \arguments{ -\item{dataset}{Input dataset. +\item{dataset}{Input dataset -The column specified by the \code{age_var} argument is expected.} +The variables specified by the \code{age_var} argument(s) to be expected.} \item{age_var}{Age variable. diff --git a/man/derive_var_analysis_ratio.Rd b/man/derive_var_analysis_ratio.Rd index 6272963e46..d7b3059558 100644 --- a/man/derive_var_analysis_ratio.Rd +++ b/man/derive_var_analysis_ratio.Rd @@ -7,7 +7,9 @@ derive_var_analysis_ratio(dataset, numer_var, denom_var, new_var = NULL) } \arguments{ -\item{dataset}{Input dataset} +\item{dataset}{Input dataset + +The variables specified by the \code{numer_var} and \code{denom_var} argument(s) to be expected.} \item{numer_var}{Variable containing numeric values to be used in the numerator of the ratio calculation.} diff --git a/man/derive_var_anrind.Rd b/man/derive_var_anrind.Rd index 6329f74bc4..b7a0999c7f 100644 --- a/man/derive_var_anrind.Rd +++ b/man/derive_var_anrind.Rd @@ -7,7 +7,9 @@ derive_var_anrind(dataset, use_a1hia1lo = FALSE) } \arguments{ -\item{dataset}{The input dataset} +\item{dataset}{Input dataset +\code{ANRLO}, \code{ANRHI}, and \code{AVAL} are expected and if \code{use_a1hia1lo} is set to \code{TRUE}, +\code{A1LO} and \code{A1H1} are expected as well.} \item{use_a1hia1lo}{A logical value indicating whether to use \code{A1H1} and \code{A1LO} in the derivation of \code{ANRIND}.} diff --git a/man/derive_var_atoxgr.Rd b/man/derive_var_atoxgr.Rd index dab904a4e0..66fc8051ad 100644 --- a/man/derive_var_atoxgr.Rd +++ b/man/derive_var_atoxgr.Rd @@ -11,10 +11,10 @@ derive_var_atoxgr( ) } \arguments{ -\item{dataset}{Input data set +\item{dataset}{Input dataset -The columns \code{ATOXGRL}, \code{ATOXGRH} and specified by \code{lotox_description_var}, -and \code{hitox_description_var} parameters are expected.} +The variables specified by the \code{lotox_description_var} and \code{hitox_description_var} argument(s) to be expected. +\code{ATOXGRL}, and \code{ATOXGRH} are expected as well.} \item{lotox_description_var}{Variable containing the toxicity grade description for low values, eg. "Anemia"} diff --git a/man/derive_var_atoxgr_dir.Rd b/man/derive_var_atoxgr_dir.Rd index ed8e9b40d3..d9b2d5719b 100644 --- a/man/derive_var_atoxgr_dir.Rd +++ b/man/derive_var_atoxgr_dir.Rd @@ -15,9 +15,9 @@ derive_var_atoxgr_dir( ) } \arguments{ -\item{dataset}{Input data set +\item{dataset}{Input dataset -The columns specified by \code{tox_description_var} parameter is expected.} +The variables specified by the \code{tox_description_var} argument(s) to be expected.} \item{new_var}{Name of the character grade variable to create, for example, \code{ATOXGRH} or \code{ATOXGRL}.} diff --git a/man/derive_var_base.Rd b/man/derive_var_base.Rd index 807057db36..aa4e90c893 100644 --- a/man/derive_var_base.Rd +++ b/man/derive_var_base.Rd @@ -13,7 +13,9 @@ derive_var_base( ) } \arguments{ -\item{dataset}{The input dataset} +\item{dataset}{Input dataset + +The variables specified by the \code{by_vars} and \code{source_var} argument(s) to be expected.} \item{by_vars}{Grouping variables uniquely identifying a set of records for which to calculate \code{new_var}} diff --git a/man/derive_var_basetype.Rd b/man/derive_var_basetype.Rd deleted file mode 100644 index c6a14589ef..0000000000 --- a/man/derive_var_basetype.Rd +++ /dev/null @@ -1,58 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_var_basetype.R -\name{derive_var_basetype} -\alias{derive_var_basetype} -\title{Derive Basetype Variable} -\usage{ -derive_var_basetype(dataset, basetypes) -} -\arguments{ -\item{dataset}{Input dataset - -The columns specified in the expressions inside \code{basetypes} are required.} - -\item{basetypes}{A \emph{named} list of expressions created using the -\code{rlang::exprs()} function - -The names corresponds to the values of the newly created \code{BASETYPE} variables -and the expressions are used to subset the input dataset.} -} -\value{ -The input dataset with variable \code{BASETYPE} added -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{derive_basetype_records()} instead. - -Baseline Type \code{BASETYPE} is needed when there is more than one definition of -baseline for a given Analysis Parameter \code{PARAM} in the same dataset. For a -given parameter, if Baseline Value \code{BASE} is populated, and there is more than -one definition of baseline, then \code{BASETYPE} must be non-null on all records of -any type for that parameter. Each value of \code{BASETYPE} refers to a definition of -baseline that characterizes the value of \code{BASE} on that row. Please see -section 4.2.1.6 of the ADaM Implementation Guide, version 1.3 for further -background. - -Adds the \code{BASETYPE} variable to a dataset and duplicates records based upon -the provided conditions. -} -\details{ -For each element of \code{basetypes} the input dataset is subset based upon -the provided expression and the \code{BASETYPE} variable is set to the name of the -expression. Then, all subsets are stacked. Records which do not match any -condition are kept and \code{BASETYPE} is set to \code{NA}. -} -\seealso{ -Other deprecated: -\code{\link{derive_param_extreme_event}()}, -\code{\link{derive_var_confirmation_flag}()}, -\code{\link{derive_var_last_dose_amt}()}, -\code{\link{derive_var_last_dose_date}()}, -\code{\link{derive_var_last_dose_grp}()}, -\code{\link{derive_var_merged_cat}()}, -\code{\link{derive_var_merged_character}()}, -\code{\link{derive_vars_last_dose}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/derive_var_chg.Rd b/man/derive_var_chg.Rd index 5a0b8de486..8a8df5a60b 100644 --- a/man/derive_var_chg.Rd +++ b/man/derive_var_chg.Rd @@ -7,8 +7,7 @@ derive_var_chg(dataset) } \arguments{ -\item{dataset}{The input dataset. Required variables are \code{AVAL} and -\code{BASE}.} +\item{dataset}{Input dataset \code{AVAL} and \code{BASE} are expected.} } \value{ The input dataset with an additional column named \code{CHG} diff --git a/man/derive_var_confirmation_flag.Rd b/man/derive_var_confirmation_flag.Rd deleted file mode 100644 index 4496c7ee81..0000000000 --- a/man/derive_var_confirmation_flag.Rd +++ /dev/null @@ -1,207 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_var_joined_exist_flag.R -\name{derive_var_confirmation_flag} -\alias{derive_var_confirmation_flag} -\title{Derive Confirmation Flag} -\usage{ -derive_var_confirmation_flag( - dataset, - by_vars, - order, - new_var, - tmp_obs_nr_var = NULL, - join_vars, - join_type, - first_cond = NULL, - filter, - true_value = "Y", - false_value = NA_character_, - check_type = "warning" -) -} -\arguments{ -\item{dataset}{Input dataset - -The variables specified by the \code{by_vars} and \code{join_vars} parameter are -expected.} - -\item{by_vars}{By variables - -The specified variables are used as by variables for joining the input -dataset with itself.} - -\item{order}{Order - -The observations are ordered by the specified order.} - -\item{new_var}{New variable - -The specified variable is added to the input dataset.} - -\item{tmp_obs_nr_var}{Temporary observation number - -The specified variable is added to the input dataset and set to the -observation number with respect to \code{order}. For each by group (\code{by_vars}) -the observation number starts with \code{1}. The variable can be used in the -conditions (\code{filter}, \code{first_cond}). It is not included in the output -dataset. It can be used to flag consecutive observations or the last -observation (see last example below).} - -\item{join_vars}{Variables to keep from joined dataset - -The variables needed from the other observations should be specified -for this parameter. The specified variables are added to the joined dataset -with suffix ".join". For example to flag all observations with \code{AVALC == "Y"} and \code{AVALC == "Y"} for at least one subsequent visit \code{join_vars = exprs(AVALC, AVISITN)} and \code{filter = AVALC == "Y" & AVALC.join == "Y" & AVISITN < AVISITN.join} could be specified. - -The \verb{*.join} variables are not included in the output dataset.} - -\item{join_type}{Observations to keep after joining - -The argument determines which of the joined observations are kept with -respect to the original observation. For example, if \code{join_type = "after"} -is specified all observations after the original observations are kept. - -For example for confirmed response or BOR in the oncology setting or -confirmed deterioration in questionnaires the confirmatory assessment must -be after the assessment to be flagged. Thus \code{join_type = "after"} could be -used. - -Whereas, sometimes you might allow for confirmatory observations to occur -prior to the observation to be flagged. For example, to flag AEs occurring -on or after seven days before a COVID AE. Thus \code{join_type = "all"} could be -used. - -\emph{Permitted Values:} \code{"before"}, \code{"after"}, \code{"all"}} - -\item{first_cond}{Condition for selecting range of data - -If this argument is specified, the other observations are restricted up to -the first observation where the specified condition is fulfilled. If the -condition is not fulfilled for any of the other observations, no -observations are considered, i.e., the observation is not flagged. - -This parameter should be specified if \code{filter} contains summary functions -which should not apply to all observations but only up to the confirmation -assessment. For an example see the third example below.} - -\item{filter}{Condition for selecting observations - -The filter is applied to the joined dataset for flagging the confirmed -observations. The condition can include summary functions. The joined -dataset is grouped by the original observations. I.e., the summary function -are applied to all observations up to the confirmation observation. For -example, \code{filter = AVALC == "CR" & all(AVALC.join \%in\% c("CR", "NE")) & count_vals(var = AVALC.join, val = "NE") <= 1} selects observations with -response "CR" and for all observations up to the confirmation observation -the response is "CR" or "NE" and there is at most one "NE".} - -\item{true_value}{Value of \code{new_var} for flagged observations - -\emph{Default}: \code{"Y"}} - -\item{false_value}{Value of \code{new_var} for observations not flagged - -\emph{Default}: \code{NA_character_}} - -\item{check_type}{Check uniqueness? - -If \code{"warning"} or \code{"error"} is specified, the specified message is issued -if the observations of the input dataset are not unique with respect to the -by variables and the order. - -\emph{Default:} \code{"warning"} - -\emph{Permitted Values:} \code{"none"}, \code{"warning"}, \code{"error"}} -} -\value{ -The input dataset with the variable specified by \code{new_var} added. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{derive_var_joined_exist_flag()} instead. -} -\details{ -The following steps are performed to produce the output dataset. -\subsection{Step 1}{ - -The input dataset is joined with itself by the variables specified for -\code{by_vars}. From the right hand side of the join only the variables -specified for \code{join_vars} are kept. The suffix ".join" is added to these -variables. - -For example, for \code{by_vars = USUBJID}, \code{join_vars = exprs(AVISITN, AVALC)} and input dataset - -\if{html}{\out{
}}\preformatted{# A tibble: 2 x 4 -USUBJID AVISITN AVALC AVAL - -1 1 Y 1 -1 2 N 0 -}\if{html}{\out{
}} - -the joined dataset is - -\if{html}{\out{
}}\preformatted{A tibble: 4 x 6 -USUBJID AVISITN AVALC AVAL AVISITN.join AVALC.join - -1 1 Y 1 1 Y -1 1 Y 1 2 N -1 2 N 0 1 Y -1 2 N 0 2 N -}\if{html}{\out{
}} -} - -\subsection{Step 2}{ - -The joined dataset is restricted to observations with respect to -\code{join_type} and \code{order}. - -The dataset from the example in the previous step with \code{join_type = "after"} and \code{order = exprs(AVISITN)} is restricted to - -\if{html}{\out{
}}\preformatted{A tibble: 4 x 6 -USUBJID AVISITN AVALC AVAL AVISITN.join AVALC.join - -1 1 Y 1 2 N -}\if{html}{\out{
}} -} - -\subsection{Step 3}{ - -If \code{first_cond} is specified, for each observation of the input dataset the -joined dataset is restricted to observations up to the first observation -where \code{first_cond} is fulfilled (the observation fulfilling the condition -is included). If for an observation of the input dataset the condition is -not fulfilled, the observation is removed. -} - -\subsection{Step 4}{ - -The joined dataset is grouped by the observations from the input dataset -and restricted to the observations fulfilling the condition specified by -\code{filter}. -} - -\subsection{Step 5}{ - -The first observation of each group is selected -} - -\subsection{Step 6}{ - -The variable specified by \code{new_var} is added to the input dataset. It is -set to \code{true_value} for all observations which were selected in the -previous step. For the other observations it is set to \code{false_value}. -} -} -\seealso{ -Other deprecated: -\code{\link{derive_param_extreme_event}()}, -\code{\link{derive_var_basetype}()}, -\code{\link{derive_var_last_dose_amt}()}, -\code{\link{derive_var_last_dose_date}()}, -\code{\link{derive_var_last_dose_grp}()}, -\code{\link{derive_var_merged_cat}()}, -\code{\link{derive_var_merged_character}()}, -\code{\link{derive_vars_last_dose}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/derive_var_dthcaus.Rd b/man/derive_var_dthcaus.Rd index b94ba192d9..f4959dc96d 100644 --- a/man/derive_var_dthcaus.Rd +++ b/man/derive_var_dthcaus.Rd @@ -12,9 +12,9 @@ derive_var_dthcaus( ) } \arguments{ -\item{dataset}{Input dataset. +\item{dataset}{Input dataset -The variables specified by \code{subject_keys} are required.} +The variables specified by the \code{subject_keys} argument(s) to be expected.} \item{...}{Objects of class "dthcaus_source" created by \code{\link[=dthcaus_source]{dthcaus_source()}}.} diff --git a/man/derive_var_extreme_dt.Rd b/man/derive_var_extreme_dt.Rd index 33eca0f7de..e9052f35eb 100644 --- a/man/derive_var_extreme_dt.Rd +++ b/man/derive_var_extreme_dt.Rd @@ -16,7 +16,7 @@ derive_var_extreme_dt( \arguments{ \item{dataset}{Input dataset -The variables specified by \code{subject_keys} are required.} +The variables specified by the \code{subject_keys} argument(s) to be expected.} \item{new_var}{Name of variable to create} diff --git a/man/derive_var_extreme_dtm.Rd b/man/derive_var_extreme_dtm.Rd index 2a891d5d13..309e593770 100644 --- a/man/derive_var_extreme_dtm.Rd +++ b/man/derive_var_extreme_dtm.Rd @@ -16,7 +16,7 @@ derive_var_extreme_dtm( \arguments{ \item{dataset}{Input dataset -The variables specified by \code{subject_keys} are required.} +The variables specified by the \code{subject_keys} argument(s) to be expected.} \item{new_var}{Name of variable to create} diff --git a/man/derive_var_extreme_flag.Rd b/man/derive_var_extreme_flag.Rd index acc55fa615..0375ef0309 100644 --- a/man/derive_var_extreme_flag.Rd +++ b/man/derive_var_extreme_flag.Rd @@ -10,6 +10,8 @@ derive_var_extreme_flag( order, new_var, mode, + true_value = "Y", + false_value = NA_character_, flag_all = FALSE, check_type = "warning" ) @@ -17,7 +19,7 @@ derive_var_extreme_flag( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} parameter are expected.} +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{by_vars}{Grouping variables @@ -32,8 +34,8 @@ Permitted Values: list of variables or functions of variables} \item{new_var}{Variable to add -The specified variable is added to the output dataset. It is set to \code{"Y"} -for the first or last observation (depending on the mode) of each by group. +The specified variable is added to the output dataset. It is set to the value +set in \code{true_value} for the first or last observation (depending on the mode) of each by group. Permitted Values: list of name-value pairs} @@ -43,6 +45,20 @@ Determines of the first or last observation is flagged. Permitted Values: \code{"first"}, \code{"last"}} +\item{true_value}{True value + +The value for the specified variable \code{new_var}, applicable to +the first or last observation (depending on the mode) of each by group. + +Permitted Values: An atomic scalar} + +\item{false_value}{False value + +The value for the specified variable \code{new_var}, NOT applicable to +the first or last observation (depending on the mode) of each by group. + +Permitted Values: An atomic scalar} + \item{flag_all}{Flag setting A logical value where if set to \code{TRUE}, all records are flagged diff --git a/man/derive_var_joined_exist_flag.Rd b/man/derive_var_joined_exist_flag.Rd index 21321c43dd..b1f6f4455d 100644 --- a/man/derive_var_joined_exist_flag.Rd +++ b/man/derive_var_joined_exist_flag.Rd @@ -22,8 +22,7 @@ derive_var_joined_exist_flag( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} and \code{join_vars} parameter are -expected.} +The variables specified by the \code{by_vars} and \code{join_vars} argument(s) to be expected.} \item{by_vars}{By variables diff --git a/man/derive_var_last_dose_amt.Rd b/man/derive_var_last_dose_amt.Rd deleted file mode 100644 index 2957c5ef0b..0000000000 --- a/man/derive_var_last_dose_amt.Rd +++ /dev/null @@ -1,90 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_var_last_dose_amt.R -\name{derive_var_last_dose_amt} -\alias{derive_var_last_dose_amt} -\title{Derive Last Dose Amount} -\usage{ -derive_var_last_dose_amt( - dataset, - dataset_ex, - filter_ex = NULL, - by_vars = exprs(STUDYID, USUBJID), - dose_id = exprs(), - dose_date, - analysis_date, - single_dose_condition = (EXDOSFRQ == "ONCE"), - new_var, - dose_var = EXDOSE, - traceability_vars = NULL -) -} -\arguments{ -\item{dataset}{Input dataset. -The variables specified by the \code{by_vars} and \code{analysis_date} parameters are expected.} - -\item{dataset_ex}{Input EX dataset. -The variables specified by the \code{by_vars}, \code{dose_date}, \code{new_vars} parameters, -and source variables from \code{traceability_vars} parameter are expected.} - -\item{filter_ex}{Filtering condition applied to EX dataset. -For example, it can be used to filter for valid dose. -Defaults to NULL.} - -\item{by_vars}{Variables to join by (created by \code{rlang::exprs}).} - -\item{dose_id}{Variables to identify unique dose (created by \code{rlang::exprs}). -Defaults to empty \code{exprs()}.} - -\item{dose_date}{The EX dose date variable. A date or date-time object is expected.} - -\item{analysis_date}{The analysis date variable. A date or date-time object is expected.} - -\item{single_dose_condition}{The condition for checking if \code{dataset_ex} is single dose. An error -is issued if the condition is not true. Defaults to \code{(EXDOSFRQ == "ONCE")}.} - -\item{new_var}{The new variable added to \code{dataset}.} - -\item{dose_var}{The EX source dose amount variable. Defaults to \code{EXDOSE}.} - -\item{traceability_vars}{A named list returned by \code{\link[=exprs]{exprs()}} listing the traceability variables, -e.g. \code{exprs(LDOSEDOM = "EX", LDOSESEQ = EXSEQ)}. -The left-hand side (names of the list elements) gives the names of the traceability variables -in the returned dataset. -The right-hand side (values of the list elements) gives the values of the traceability variables -in the returned dataset. -These can be either strings or symbols referring to existing variables.} -} -\value{ -Input dataset with additional column \code{new_var}. -} -\description{ -Add a variable for dose amount from the last dose to the input dataset. - -\strong{Note:} This is a wrapper function for the function \code{derive_vars_last_dose()}. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{derive_vars_joined()} instead. -} -\details{ -The last dose amount is derived as the dose amount where the maximum \code{dose_date} is -lower to or equal to the \code{analysis_date} per \code{by_vars} for each observation in \code{dataset}. - -If dose information is aggregated (i.e. is a dosing frequency other than \code{"ONCE"} -over a period defined by a start and end date) the function -\code{create_single_dose_dataset()} can be used to generate single doses from -aggregate dose information and satisfy \code{single_dose_condition}. -} -\seealso{ -Other deprecated: -\code{\link{derive_param_extreme_event}()}, -\code{\link{derive_var_basetype}()}, -\code{\link{derive_var_confirmation_flag}()}, -\code{\link{derive_var_last_dose_date}()}, -\code{\link{derive_var_last_dose_grp}()}, -\code{\link{derive_var_merged_cat}()}, -\code{\link{derive_var_merged_character}()}, -\code{\link{derive_vars_last_dose}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/derive_var_last_dose_date.Rd b/man/derive_var_last_dose_date.Rd deleted file mode 100644 index 40323b807f..0000000000 --- a/man/derive_var_last_dose_date.Rd +++ /dev/null @@ -1,94 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_var_last_dose_date.R -\name{derive_var_last_dose_date} -\alias{derive_var_last_dose_date} -\title{Derive Last Dose Date-Time} -\usage{ -derive_var_last_dose_date( - dataset, - dataset_ex, - filter_ex = NULL, - by_vars = exprs(STUDYID, USUBJID), - dose_id = exprs(), - dose_date, - analysis_date, - single_dose_condition = (EXDOSFRQ == "ONCE"), - new_var, - output_datetime = TRUE, - traceability_vars = NULL -) -} -\arguments{ -\item{dataset}{Input dataset. -The variables specified by the \code{by_vars} and \code{analysis_date} parameters are expected.} - -\item{dataset_ex}{Input EX dataset. -The variables specified by the \code{by_vars}, \code{dose_date}, \code{new_vars} parameters, -and source variables from \code{traceability_vars} parameter are expected.} - -\item{filter_ex}{Filtering condition applied to EX dataset. -For example, it can be used to filter for valid dose. -Defaults to NULL.} - -\item{by_vars}{Variables to join by (created by \code{rlang::exprs}).} - -\item{dose_id}{Variables to identify unique dose (created by \code{rlang::exprs}). -Defaults to empty \code{exprs()}.} - -\item{dose_date}{The EX dose date variable. A date or date-time object is expected.} - -\item{analysis_date}{The analysis date variable. A date or date-time object is expected.} - -\item{single_dose_condition}{The condition for checking if \code{dataset_ex} is single dose. An error -is issued if the condition is not true. Defaults to \code{(EXDOSFRQ == "ONCE")}.} - -\item{new_var}{The new date or datetime variable added to \code{dataset}.} - -\item{output_datetime}{Display \code{new_var} as datetime or as date only. Defaults to \code{TRUE}.} - -\item{traceability_vars}{A named list returned by \code{\link[=exprs]{exprs()}} listing the traceability variables, -e.g. \code{exprs(LDOSEDOM = "EX", LDOSESEQ = EXSEQ)}. -The left-hand side (names of the list elements) gives the names of the traceability variables -in the returned dataset. -The right-hand side (values of the list elements) gives the values of the traceability variables -in the returned dataset. -These can be either strings or symbols referring to existing variables.} -} -\value{ -Input dataset with additional column \code{new_var}. -} -\description{ -Add a variable for the dose date or datetime of the last dose to -the input dataset. - -\strong{Note:} This is a wrapper function for the function \code{derive_vars_last_dose()}. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{derive_vars_joined()} instead. -} -\details{ -The last dose date is derived as the maximum dose date where the -\code{dose_date} is lower to or equal to the \code{analysis_date} per \code{by_vars} for -each observation in \code{dataset}. When \code{output_datetime} is \code{TRUE} and time is -missing, then the last dose date time is imputed to \code{00:00:00}. However, if -date is missing, then no imputation is done. - -If dose information is aggregated (i.e. is a dosing frequency other than \code{"ONCE"} -over a period defined by a start and end date) the function -\code{create_single_dose_dataset()} can be used to generate single doses from -aggregate dose information and satisfy \code{single_dose_condition}. -} -\seealso{ -Other deprecated: -\code{\link{derive_param_extreme_event}()}, -\code{\link{derive_var_basetype}()}, -\code{\link{derive_var_confirmation_flag}()}, -\code{\link{derive_var_last_dose_amt}()}, -\code{\link{derive_var_last_dose_grp}()}, -\code{\link{derive_var_merged_cat}()}, -\code{\link{derive_var_merged_character}()}, -\code{\link{derive_vars_last_dose}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/derive_var_last_dose_grp.Rd b/man/derive_var_last_dose_grp.Rd deleted file mode 100644 index 626c9eb31f..0000000000 --- a/man/derive_var_last_dose_grp.Rd +++ /dev/null @@ -1,111 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_var_last_dose_grp.R -\name{derive_var_last_dose_grp} -\alias{derive_var_last_dose_grp} -\title{Derive Last Dose with User-Defined Groupings} -\usage{ -derive_var_last_dose_grp( - dataset, - dataset_ex, - filter_ex = NULL, - by_vars = exprs(STUDYID, USUBJID), - dose_id = exprs(), - dose_date, - analysis_date, - single_dose_condition = (EXDOSFRQ == "ONCE"), - new_var, - grp_brks, - grp_lbls, - include_lowest = TRUE, - right = TRUE, - dose_var = EXDOSE, - traceability_vars = NULL -) -} -\arguments{ -\item{dataset}{Input dataset. -The variables specified by the \code{by_vars} and \code{analysis_date} parameters are expected.} - -\item{dataset_ex}{Input EX dataset. -The variables specified by the \code{by_vars}, \code{dose_date}, \code{new_vars} parameters, -and source variables from \code{traceability_vars} parameter are expected.} - -\item{filter_ex}{Filtering condition applied to EX dataset. -For example, it can be used to filter for valid dose. -Defaults to NULL.} - -\item{by_vars}{Variables to join by (created by \code{rlang::exprs}).} - -\item{dose_id}{Variables to identify unique dose (created by \code{rlang::exprs}). -Defaults to empty \code{exprs()}.} - -\item{dose_date}{The EX dose date variable. A date or date-time object is expected.} - -\item{analysis_date}{The analysis date variable. A date or date-time object is expected.} - -\item{single_dose_condition}{The condition for checking if \code{dataset_ex} is single dose. An error -is issued if the condition is not true. Defaults to \code{(EXDOSFRQ == "ONCE")}.} - -\item{new_var}{The output variable defined by the user.} - -\item{grp_brks}{User supplied breaks to apply to groups. -Refer to \code{breaks} parameter in \code{cut()} for details.} - -\item{grp_lbls}{User supplied labels to apply to groups. -Refer to \code{labels} parameter in \code{cut()} for details.} - -\item{include_lowest}{logical, indicating if a value equal to the lowest -(or highest, for right = FALSE) ‘breaks’ value should be included. -Refer to \code{include.lowest} parameter in \code{cut()} for details.} - -\item{right}{Logical, indicating if the intervals should be closed on the right -(and open on the left) or vice versa. -Refer to \code{right} parameter in \code{cut()} for details.} - -\item{dose_var}{The source dose amount variable. Defaults to \code{EXDOSE}.} - -\item{traceability_vars}{A named list returned by \code{\link[=exprs]{exprs()}} listing the traceability variables, -e.g. \code{exprs(LDOSEDOM = "EX", LDOSESEQ = EXSEQ)}. -The left-hand side (names of the list elements) gives the names of the traceability variables -in the returned dataset. -The right-hand side (values of the list elements) gives the values of the traceability variables -in the returned dataset. -These can be either strings or symbols referring to existing variables.} -} -\value{ -Input dataset with additional column \code{new_var}. -} -\description{ -Add a variable for user-defined dose grouping of the last dose -to the input dataset. - -\strong{Note:} This is a wrapper function for the function \code{derive_vars_last_dose()}. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{derive_vars_joined()} instead. -} -\details{ -Last dose is the dose with maximum \code{dose_date} that is lower to or equal to the -\code{analysis_date} per \code{by_vars} for each observation in \code{dataset}. -The last dose group is then derived by user-defined grouping, which groups -\code{dose_var} as specified in \code{grp_brks}, and returns \code{grp_lbls} as the values for \code{new_var}. - -If dose information is aggregated (i.e. is a dosing frequency other than \code{"ONCE"} -over a period defined by a start and end date) the function -\code{create_single_dose_dataset()} can be used to generate single doses from -aggregate dose information and satisfy \code{single_dose_condition}. -} -\seealso{ -Other deprecated: -\code{\link{derive_param_extreme_event}()}, -\code{\link{derive_var_basetype}()}, -\code{\link{derive_var_confirmation_flag}()}, -\code{\link{derive_var_last_dose_amt}()}, -\code{\link{derive_var_last_dose_date}()}, -\code{\link{derive_var_merged_cat}()}, -\code{\link{derive_var_merged_character}()}, -\code{\link{derive_vars_last_dose}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/derive_var_merged_cat.Rd b/man/derive_var_merged_cat.Rd deleted file mode 100644 index 3a6249e272..0000000000 --- a/man/derive_var_merged_cat.Rd +++ /dev/null @@ -1,126 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_merged.R -\name{derive_var_merged_cat} -\alias{derive_var_merged_cat} -\title{Merge a Categorization Variable} -\usage{ -derive_var_merged_cat( - dataset, - dataset_add, - by_vars, - order = NULL, - new_var, - source_var, - cat_fun, - filter_add = NULL, - mode = NULL, - missing_value = NA_character_ -) -} -\arguments{ -\item{dataset}{Input dataset - -The variables specified by the \code{by_vars} argument are expected.} - -\item{dataset_add}{Additional dataset - -The variables specified by the \code{by_vars}, the \code{source_var}, and the \code{order} -argument are expected.} - -\item{by_vars}{Grouping variables - -The input dataset and the selected observations from the additional dataset -are merged by the specified by variables. The by variables must be a unique -key of the selected observations. Variables from the additional dataset can -be renamed by naming the element, i.e., \verb{by_vars = exprs( = )}, similar to -the dplyr joins. - -\emph{Permitted Values}: list of variables created by \code{exprs()}} - -\item{order}{Sort order - -If the argument is set to a non-null value, for each by group the first or -last observation from the additional dataset is selected with respect to the -specified order. - -Variables defined by the \code{new_vars} argument can be used in the sort order. - -\emph{Permitted Values}: list of expressions created by \code{exprs()}, e.g., -\code{exprs(ADT, desc(AVAL))} or \code{NULL}} - -\item{new_var}{New variable - -The specified variable is added to the additional dataset and set to the -categorized values, i.e., \verb{cat_fun()}.} - -\item{source_var}{Source variable} - -\item{cat_fun}{Categorization function - -A function must be specified for this argument which expects the values of -the source variable as input and returns the categorized values.} - -\item{filter_add}{Filter for additional dataset (\code{dataset_add}) - -Only observations fulfilling the specified condition are taken into account -for merging. If the argument is not specified, all observations are -considered. - -Variables defined by the \code{new_vars} argument can be used in the filter -condition. - -\emph{Permitted Values}: a condition} - -\item{mode}{Selection mode - -Determines if the first or last observation is selected. If the \code{order} -argument is specified, \code{mode} must be non-null. - -If the \code{order} argument is not specified, the \code{mode} argument is ignored. - -\emph{Permitted Values}: \code{"first"}, \code{"last"}, \code{NULL}} - -\item{missing_value}{Values used for missing information - -The new variable is set to the specified value for all by groups without -observations in the additional dataset. - -\emph{Default}: \code{NA_character_}} -} -\value{ -The output dataset contains all observations and variables of the -input dataset and additionally the variable specified for \code{new_var} derived -from the additional dataset (\code{dataset_add}). -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{derive_vars_merged()} instead. - -Merge a categorization variable from a dataset to the input dataset. The -observations to merge can be selected by a condition and/or selecting the -first or last observation for each by group. -} -\details{ -\enumerate{ -\item The additional dataset is restricted to the observations matching the -\code{filter_add} condition. -\item The categorization variable is added to the additional dataset. -\item If \code{order} is specified, for each by group the first or last observation -(depending on \code{mode}) is selected. -\item The categorization variable is merged to the input dataset. -} -} -\seealso{ -Other deprecated: -\code{\link{derive_param_extreme_event}()}, -\code{\link{derive_var_basetype}()}, -\code{\link{derive_var_confirmation_flag}()}, -\code{\link{derive_var_last_dose_amt}()}, -\code{\link{derive_var_last_dose_date}()}, -\code{\link{derive_var_last_dose_grp}()}, -\code{\link{derive_var_merged_character}()}, -\code{\link{derive_vars_last_dose}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/derive_var_merged_character.Rd b/man/derive_var_merged_character.Rd deleted file mode 100644 index a9186d60c4..0000000000 --- a/man/derive_var_merged_character.Rd +++ /dev/null @@ -1,131 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_merged.R -\name{derive_var_merged_character} -\alias{derive_var_merged_character} -\title{Merge a Character Variable} -\usage{ -derive_var_merged_character( - dataset, - dataset_add, - by_vars, - order = NULL, - new_var, - source_var, - case = NULL, - filter_add = NULL, - mode = NULL, - missing_value = NA_character_ -) -} -\arguments{ -\item{dataset}{Input dataset - -The variables specified by the \code{by_vars} argument are expected.} - -\item{dataset_add}{Additional dataset - -The variables specified by the \code{by_vars}, the \code{source_var}, and the \code{order} -argument are expected.} - -\item{by_vars}{Grouping variables - -The input dataset and the selected observations from the additional dataset -are merged by the specified by variables. The by variables must be a unique -key of the selected observations. Variables from the additional dataset can -be renamed by naming the element, i.e., \verb{by_vars = exprs( = )}, similar to -the dplyr joins. - -\emph{Permitted Values}: list of variables created by \code{exprs()}} - -\item{order}{Sort order - -If the argument is set to a non-null value, for each by group the first or -last observation from the additional dataset is selected with respect to the -specified order. - -Variables defined by the \code{new_vars} argument can be used in the sort order. - -\emph{Permitted Values}: list of expressions created by \code{exprs()}, e.g., -\code{exprs(ADT, desc(AVAL))} or \code{NULL}} - -\item{new_var}{New variable - -The specified variable is added to the additional dataset and set to the -transformed value with respect to the \code{case} argument.} - -\item{source_var}{Source variable} - -\item{case}{Change case - -Changes the case of the values of the new variable. - -\emph{Default}: \code{NULL} - -\emph{Permitted Values}: \code{NULL}, \code{"lower"}, \code{"upper"}, \code{"title"}} - -\item{filter_add}{Filter for additional dataset (\code{dataset_add}) - -Only observations fulfilling the specified condition are taken into account -for merging. If the argument is not specified, all observations are -considered. - -Variables defined by the \code{new_vars} argument can be used in the filter -condition. - -\emph{Permitted Values}: a condition} - -\item{mode}{Selection mode - -Determines if the first or last observation is selected. If the \code{order} -argument is specified, \code{mode} must be non-null. - -If the \code{order} argument is not specified, the \code{mode} argument is ignored. - -\emph{Permitted Values}: \code{"first"}, \code{"last"}, \code{NULL}} - -\item{missing_value}{Values used for missing information - -The new variable is set to the specified value for all by groups without -observations in the additional dataset. - -\emph{Default}: \code{NA_character_} - -\emph{Permitted Value}: A character scalar} -} -\value{ -The output dataset contains all observations and variables of the -input dataset and additionally the variable specified for \code{new_var} derived -from the additional dataset (\code{dataset_add}). -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{derive_vars_merged()} instead. - -Merge a character variable from a dataset to the input dataset. The -observations to merge can be selected by a condition and/or selecting the -first or last observation for each by group. -} -\details{ -\enumerate{ -\item The additional dataset is restricted to the observations matching the -\code{filter_add} condition. -\item The (transformed) character variable is added to the additional dataset. -\item If \code{order} is specified, for each by group the first or last observation -(depending on \code{mode}) is selected. -\item The character variable is merged to the input dataset. -} -} -\seealso{ -Other deprecated: -\code{\link{derive_param_extreme_event}()}, -\code{\link{derive_var_basetype}()}, -\code{\link{derive_var_confirmation_flag}()}, -\code{\link{derive_var_last_dose_amt}()}, -\code{\link{derive_var_last_dose_date}()}, -\code{\link{derive_var_last_dose_grp}()}, -\code{\link{derive_var_merged_cat}()}, -\code{\link{derive_vars_last_dose}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/derive_var_merged_exist_flag.Rd b/man/derive_var_merged_exist_flag.Rd index b86c0ef87b..ae0728a4bd 100644 --- a/man/derive_var_merged_exist_flag.Rd +++ b/man/derive_var_merged_exist_flag.Rd @@ -19,7 +19,7 @@ derive_var_merged_exist_flag( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} argument are expected.} +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{dataset_add}{Additional dataset diff --git a/man/derive_var_merged_summary.Rd b/man/derive_var_merged_summary.Rd index 5a7ff2fd0f..08220316cb 100644 --- a/man/derive_var_merged_summary.Rd +++ b/man/derive_var_merged_summary.Rd @@ -2,12 +2,13 @@ % Please edit documentation in R/derive_merged.R \name{derive_var_merged_summary} \alias{derive_var_merged_summary} -\title{Merge a Summary Variable} +\title{Merge Summary Variables} \usage{ derive_var_merged_summary( dataset, dataset_add, by_vars, + new_vars = NULL, new_var, filter_add = NULL, analysis_var, @@ -17,23 +18,45 @@ derive_var_merged_summary( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} argument are expected.} +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{dataset_add}{Additional dataset -The variables specified by the \code{by_vars} and the \code{analysis_var} arguments -are expected.} +The variables specified by the \code{by_vars} and the variables used on the left +hand sides of the \code{new_vars} arguments are expected.} \item{by_vars}{Grouping variables -The values of \code{analysis_var} are summarized by the specified variables. The -summarized values are merged to the input dataset (\code{dataset}) by the -specified by variables. +The expressions on the left hand sides of \code{new_vars} are evaluated by the +specified \emph{variables}. Then the resulting values are merged to the input +dataset (\code{dataset}) by the specified \emph{variables}. \emph{Permitted Values}: list of variables created by \code{exprs()}} +\item{new_vars}{New variables to add + +The specified variables are added to the input dataset. + +A named list of expressions is expected: +\itemize{ +\item LHS refer to a variable. +\item RHS refers to the values to set to the variable. This can be a string, a +symbol, a numeric value, an expression or NA. If summary functions are +used, the values are summarized by the variables specified for \code{by_vars}. +} + +For example: + +\if{html}{\out{
}}\preformatted{ new_vars = exprs( + DOSESUM = sum(AVAL), + DOSEMEAN = mean(AVAL) + ) +}\if{html}{\out{
}}} + \item{new_var}{Variable to add +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{new_vars} instead. + The specified variable is added to the input dataset (\code{dataset}) and set to the summarized values.} @@ -47,36 +70,37 @@ considered. \item{analysis_var}{Analysis variable +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{new_vars} instead. + The values of the specified variable are summarized by the function specified for \code{summary_fun}.} \item{summary_fun}{Summary function +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{new_vars} instead. + The specified function that takes as input \code{analysis_var} and performs the calculation. This can include built-in functions as well as user defined functions, for example \code{mean} or \code{function(x) mean(x, na.rm = TRUE)}.} } \value{ The output dataset contains all observations and variables of the -input dataset and additionally the variable specified for \code{new_var}. +input dataset and additionally the variables specified for \code{new_vars}. } \description{ Merge a summary variable from a dataset to the input dataset. - -\strong{Note:} This is a wrapper function for the more generic \code{derive_vars_merged}. } \details{ \enumerate{ \item The records from the additional dataset (\code{dataset_add}) are restricted to those matching the \code{filter_add} condition. -\item The values of the analysis variable (\code{analysis_var}) are summarized by -the summary function (\code{summary_fun}) for each by group (\code{by_vars}) in the -additional dataset (\code{dataset_add}). -\item The summarized values are merged to the input dataset as a new variable -(\code{new_var}). For observations without a matching observation in the -additional dataset the new variable is set to \code{NA}. Observations in the -additional dataset which have no matching observation in the input dataset -are ignored. +\item The new variables (\code{new_vars}) are created for each by group (\code{by_vars}) +in the additional dataset (\code{dataset_add}) by calling \code{summarize()}. I.e., +all observations of a by group are summarized to a single observation. +\item The new variables are merged to the input dataset. For observations +without a matching observation in the additional dataset the new variables +are set to \code{NA}. Observations in the additional dataset which have no +matching observation in the input dataset are ignored. } } \examples{ @@ -100,9 +124,10 @@ derive_var_merged_summary( adbds, dataset_add = adbds, by_vars = exprs(USUBJID, AVISIT), - new_var = MEANVIS, - analysis_var = AVAL, - summary_fun = function(x) mean(x, na.rm = TRUE) + new_vars = exprs( + MEANVIS = mean(AVAL, na.rm = TRUE), + MAXVIS = max(AVAL, na.rm = TRUE) + ) ) # Add a variable listing the lesion ids at baseline @@ -134,9 +159,7 @@ derive_var_merged_summary( dataset_add = adtr, by_vars = exprs(USUBJID), filter_add = AVISIT == "BASELINE", - new_var = LESIONSBL, - analysis_var = LESIONID, - summary_fun = function(x) paste(x, collapse = ", ") + new_vars = exprs(LESIONSBL = paste(LESIONID, collapse = ", ")) ) } diff --git a/man/derive_var_obs_number.Rd b/man/derive_var_obs_number.Rd index f9fae3a7ee..d4c54e6881 100644 --- a/man/derive_var_obs_number.Rd +++ b/man/derive_var_obs_number.Rd @@ -15,8 +15,7 @@ derive_var_obs_number( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{order} and the \code{by_vars} parameter are -expected.} +The variables specified by the \code{by_vars} and \code{order} argument(s) to be expected.} \item{by_vars}{Grouping variables diff --git a/man/derive_var_ontrtfl.Rd b/man/derive_var_ontrtfl.Rd index be267b1b11..530c7c42a2 100644 --- a/man/derive_var_ontrtfl.Rd +++ b/man/derive_var_ontrtfl.Rd @@ -18,7 +18,7 @@ derive_var_ontrtfl( ) } \arguments{ -\item{dataset}{Input dataset. +\item{dataset}{Input dataset Required columns are \code{start_date}, \code{end_date}, \code{ref_start_date} and \code{ref_end_date}.} diff --git a/man/derive_var_pchg.Rd b/man/derive_var_pchg.Rd index 428950b05a..70b6749fcb 100644 --- a/man/derive_var_pchg.Rd +++ b/man/derive_var_pchg.Rd @@ -7,8 +7,8 @@ derive_var_pchg(dataset) } \arguments{ -\item{dataset}{The input dataset. Required variables are \code{AVAL} and -\code{BASE}.} +\item{dataset}{Input dataset +\code{AVAL} and \code{BASE} are expected.} } \value{ The input dataset with an additional column named \code{PCHG} diff --git a/man/derive_var_relative_flag.Rd b/man/derive_var_relative_flag.Rd index 9d07da3360..ac017c896d 100644 --- a/man/derive_var_relative_flag.Rd +++ b/man/derive_var_relative_flag.Rd @@ -20,8 +20,7 @@ derive_var_relative_flag( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{order} and the \code{by_vars} argument are -expected.} +The variables specified by the \code{by_vars} and \code{order} argument(s) to be expected.} \item{by_vars}{Grouping variables diff --git a/man/derive_var_shift.Rd b/man/derive_var_shift.Rd index ac4ff9fdfd..9a46f1e001 100644 --- a/man/derive_var_shift.Rd +++ b/man/derive_var_shift.Rd @@ -17,7 +17,7 @@ derive_var_shift( \arguments{ \item{dataset}{Input dataset -The columns specified by \code{from_var} and the \code{to_var} parameters are expected.} +The variables specified by the \code{from_var} and \code{to_var} argument(s) to be expected.} \item{new_var}{Name of the character shift variable to create.} diff --git a/man/derive_var_trtdurd.Rd b/man/derive_var_trtdurd.Rd index 81707b483b..940a28240e 100644 --- a/man/derive_var_trtdurd.Rd +++ b/man/derive_var_trtdurd.Rd @@ -9,8 +9,7 @@ derive_var_trtdurd(dataset, start_date = TRTSDT, end_date = TRTEDT) \arguments{ \item{dataset}{Input dataset -The columns specified by the \code{start_date} and the \code{end_date} parameter are -expected.} +The variables specified by the \code{start_date} and \code{end_date} argument(s) to be expected.} \item{start_date}{The start date diff --git a/man/derive_vars_aage.Rd b/man/derive_vars_aage.Rd index 189334d6ac..eebd490340 100644 --- a/man/derive_vars_aage.Rd +++ b/man/derive_vars_aage.Rd @@ -16,8 +16,7 @@ derive_vars_aage( \arguments{ \item{dataset}{Input dataset -The columns specified by the \code{start_date} and the \code{end_date} parameter are -expected.} +The variables specified by the \code{start_date} and \code{end_date} argument(s) to be expected.} \item{start_date}{The start date diff --git a/man/derive_vars_atc.Rd b/man/derive_vars_atc.Rd index 0f9e8f8bde..a289247569 100644 --- a/man/derive_vars_atc.Rd +++ b/man/derive_vars_atc.Rd @@ -14,7 +14,7 @@ derive_vars_atc( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} parameter are required} +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{dataset_facm}{FACM dataset diff --git a/man/derive_vars_dt.Rd b/man/derive_vars_dt.Rd index 31f545813d..b79a07db63 100644 --- a/man/derive_vars_dt.Rd +++ b/man/derive_vars_dt.Rd @@ -17,9 +17,9 @@ derive_vars_dt( ) } \arguments{ -\item{dataset}{Input dataset. +\item{dataset}{Input dataset -The date character vector (\code{dtc}) must be present.} +The variables specified by the \code{dtc} argument(s) to be expected.} \item{new_vars_prefix}{Prefix used for the output variable(s). diff --git a/man/derive_vars_dtm.Rd b/man/derive_vars_dtm.Rd index 7aed399ccd..9732dd7ddf 100644 --- a/man/derive_vars_dtm.Rd +++ b/man/derive_vars_dtm.Rd @@ -21,7 +21,7 @@ derive_vars_dtm( \arguments{ \item{dataset}{Input dataset -The date character vector (\code{dtc}) must be present.} +The variables specified by the \code{dtc} argument(s) to be expected.} \item{new_vars_prefix}{Prefix used for the output variable(s). diff --git a/man/derive_vars_dtm_to_dt.Rd b/man/derive_vars_dtm_to_dt.Rd index 0efcdcb227..769f3f93fe 100644 --- a/man/derive_vars_dtm_to_dt.Rd +++ b/man/derive_vars_dtm_to_dt.Rd @@ -7,7 +7,9 @@ derive_vars_dtm_to_dt(dataset, source_vars) } \arguments{ -\item{dataset}{Input dataset} +\item{dataset}{Input dataset + +The variables specified by the \code{source_vars} argument(s) to be expected.} \item{source_vars}{A list of datetime variables created using \code{exprs()} from which dates are to be extracted} diff --git a/man/derive_vars_dtm_to_tm.Rd b/man/derive_vars_dtm_to_tm.Rd index 2348105f90..8d4bbeaffc 100644 --- a/man/derive_vars_dtm_to_tm.Rd +++ b/man/derive_vars_dtm_to_tm.Rd @@ -7,7 +7,9 @@ derive_vars_dtm_to_tm(dataset, source_vars) } \arguments{ -\item{dataset}{Input dataset} +\item{dataset}{Input dataset + +The variables specified by the \code{source_vars} argument(s) to be expected.} \item{source_vars}{A list of datetime variables created using \code{exprs()} from which time is to be extracted} diff --git a/man/derive_vars_duration.Rd b/man/derive_vars_duration.Rd index 0dcee21daa..cb6676ab84 100644 --- a/man/derive_vars_duration.Rd +++ b/man/derive_vars_duration.Rd @@ -21,8 +21,7 @@ derive_vars_duration( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{start_date} and the \code{end_date} parameter are -expected.} +The variables specified by the \code{start_date} and \code{end_date} argument(s) to be expected.} \item{new_var}{Name of variable to create} diff --git a/man/derive_vars_dy.Rd b/man/derive_vars_dy.Rd index cc2de470cf..c0e3ddac4b 100644 --- a/man/derive_vars_dy.Rd +++ b/man/derive_vars_dy.Rd @@ -9,8 +9,7 @@ derive_vars_dy(dataset, reference_date, source_vars) \arguments{ \item{dataset}{Input dataset -The columns specified by the \code{reference_date} and the \code{source_vars} -parameter are expected.} +The variables specified by the \code{reference_date} and \code{source_vars} argument(s) to be expected.} \item{reference_date}{A date or date-time column, e.g., date of first treatment or date-time of last exposure to treatment. diff --git a/man/derive_vars_joined.Rd b/man/derive_vars_joined.Rd index 0073930145..5092e89ab8 100644 --- a/man/derive_vars_joined.Rd +++ b/man/derive_vars_joined.Rd @@ -15,6 +15,9 @@ derive_vars_joined( filter_add = NULL, filter_join = NULL, mode = NULL, + exist_flag = NULL, + true_value = "Y", + false_value = NA_character_, missing_values = NULL, check_type = "warning" ) @@ -22,7 +25,7 @@ derive_vars_joined( \arguments{ \item{dataset}{Input dataset -The variables specified by \code{by_vars} are expected.} +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{dataset_add}{Additional dataset @@ -122,6 +125,29 @@ If the \code{order} argument is not specified, the \code{mode} argument is ignor \emph{Permitted Values}: \code{"first"}, \code{"last"}, \code{NULL}} +\item{exist_flag}{Exist flag + +If the argument is specified (e.g., \code{exist_flag = FLAG}), the specified +variable (e.g., \code{FLAG}) is added to the input dataset. This variable will +be the value provided in \code{true_value} for all selected records from \code{dataset_add} +which are merged into the input dataset, and the value provided in \code{false_value} otherwise. + +\emph{Permitted Values}: Variable name} + +\item{true_value}{True value + +The value for the specified variable \code{exist_flag}, applicable to +the first or last observation (depending on the mode) of each by group. + +Permitted Values: An atomic scalar} + +\item{false_value}{False value + +The value for the specified variable \code{exist_flag}, NOT applicable to +the first or last observation (depending on the mode) of each by group. + +Permitted Values: An atomic scalar} + \item{missing_values}{Values for non-matching observations For observations of the input dataset (\code{dataset}) which do not have a diff --git a/man/derive_vars_last_dose.Rd b/man/derive_vars_last_dose.Rd deleted file mode 100644 index 3821003947..0000000000 --- a/man/derive_vars_last_dose.Rd +++ /dev/null @@ -1,114 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_vars_last_dose.R -\name{derive_vars_last_dose} -\alias{derive_vars_last_dose} -\title{Derive Last Dose} -\usage{ -derive_vars_last_dose( - dataset, - dataset_ex, - filter_ex = NULL, - by_vars = exprs(STUDYID, USUBJID), - dose_id = exprs(), - dose_date, - analysis_date, - single_dose_condition = EXDOSFRQ == "ONCE", - new_vars = NULL, - traceability_vars = NULL -) -} -\arguments{ -\item{dataset}{Input dataset. -The variables specified by the \code{by_vars} and \code{analysis_date} parameters are expected.} - -\item{dataset_ex}{Input EX dataset. -The variables specified by the \code{by_vars}, \code{dose_date}, \code{new_vars} parameters, -and source variables from \code{traceability_vars} parameter are expected.} - -\item{filter_ex}{Filtering condition applied to EX dataset. -For example, it can be used to filter for valid dose. -Defaults to NULL.} - -\item{by_vars}{Variables to join by (created by \code{rlang::exprs}).} - -\item{dose_id}{Variables to identify unique dose (created by \code{rlang::exprs}). -Defaults to empty \code{exprs()}.} - -\item{dose_date}{The EX dose date variable. A date or date-time object is expected.} - -\item{analysis_date}{The analysis date variable. A date or date-time object is expected.} - -\item{single_dose_condition}{The condition for checking if \code{dataset_ex} is single dose. An error -is issued if the condition is not true. Defaults to \code{(EXDOSFRQ == "ONCE")}.} - -\item{new_vars}{Variables to keep from \code{dataset_ex}, with the option to -rename. Can either be variables created by \code{rlang::exprs} (e.g. -\code{exprs(VISIT)}), or named list returned by \code{\link[=exprs]{exprs()}} (e.g. -\code{exprs(LSTEXVIS = VISIT)}). If set to \code{NULL}, then all variables from -\code{dataset_ex} are kept without renaming. Defaults to \code{NULL}.} - -\item{traceability_vars}{A named list returned by \code{\link[=exprs]{exprs()}} listing the traceability variables, -e.g. \code{exprs(LDOSEDOM = "EX", LDOSESEQ = EXSEQ)}. -The left-hand side (names of the list elements) gives the names of the traceability variables -in the returned dataset. -The right-hand side (values of the list elements) gives the values of the traceability variables -in the returned dataset. -These can be either strings or symbols referring to existing variables.} -} -\value{ -Input dataset with EX source variables from last dose added. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{derive_vars_joined()} instead. -} -\details{ -Add EX source variables from last dose to the input dataset. - -When doing date comparison to identify last dose, date-time imputations are done as follows: -\itemize{ -\item \code{dose_date}: time is imputed to \code{00:00:00} if the variable is a date variable -\item \code{analysis_date}: time is imputed to \code{23:59:59} if the variable is a date variable -} - -The last dose records are identified as follows: -\enumerate{ -\item The \code{dataset_ex} is filtered using \code{filter_ex}, if provided. -This is useful for, for example, filtering for valid dose only. -\item The datasets \code{dataset} and \code{dataset_ex} are joined using \code{by_vars}. -\item The last dose is identified: -the last dose is the EX record with maximum date where \code{dose_date} is lower to or equal to -\code{analysis_date}, subject to both date values are non-NA. -The last dose is identified per \code{by_vars}. -If multiple EX records exist for the same \code{dose_date}, then either \code{dose_id} -needs to be supplied (e.g. \code{dose_id = exprs(EXSEQ)}) to identify unique records, -or an error is issued. When \code{dose_id} is supplied, the last EX record from the same \code{dose_date} -sorted by \code{dose_id} will be used to identify last dose. -\item The EX source variables (as specified in \code{new_vars}) from last dose are appended to the -\code{dataset} and returned to the user. -} - -This function only works correctly for EX dataset with a structure of single dose per row. -If your study EX dataset has multiple doses per row, use \code{\link[=create_single_dose_dataset]{create_single_dose_dataset()}} to -transform the EX dataset into single dose per row structure before calling -\code{derive_vars_last_dose()}. - -If variables (other than those specified in \code{by_vars}) exist in both \code{dataset} and \code{dataset_ex}, -then join cannot be performed properly and an error is issued. To resolve the error, use -\code{new_vars} to either keep variables unique to \code{dataset_ex}, or use this option to rename -variables from \code{dataset_ex} (e.g. \code{new_vars = exprs(LSTEXVIS = VISIT)}). -} -\seealso{ -Other deprecated: -\code{\link{derive_param_extreme_event}()}, -\code{\link{derive_var_basetype}()}, -\code{\link{derive_var_confirmation_flag}()}, -\code{\link{derive_var_last_dose_amt}()}, -\code{\link{derive_var_last_dose_date}()}, -\code{\link{derive_var_last_dose_grp}()}, -\code{\link{derive_var_merged_cat}()}, -\code{\link{derive_var_merged_character}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/derive_vars_merged.Rd b/man/derive_vars_merged.Rd index 78e415ce4d..dca45a6222 100644 --- a/man/derive_vars_merged.Rd +++ b/man/derive_vars_merged.Rd @@ -13,7 +13,10 @@ derive_vars_merged( new_vars = NULL, filter_add = NULL, mode = NULL, - match_flag = NULL, + match_flag, + exist_flag = NULL, + true_value = "Y", + false_value = NA_character_, missing_values = NULL, check_type = "warning", duplicate_msg = NULL @@ -22,7 +25,7 @@ derive_vars_merged( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} argument are expected.} +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{dataset_add}{Additional dataset @@ -94,6 +97,8 @@ If the \code{order} argument is not specified, the \code{mode} argument is ignor \item{match_flag}{Match flag +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{exist_flag} instead. + If the argument is specified (e.g., \code{match_flag = FLAG}), the specified variable (e.g., \code{FLAG}) is added to the input dataset. This variable will be \code{TRUE} for all selected records from \code{dataset_add} which are merged into @@ -101,6 +106,29 @@ the input dataset, and \code{NA} otherwise. \emph{Permitted Values}: Variable name} +\item{exist_flag}{Exist flag + +If the argument is specified (e.g., \code{exist_flag = FLAG}), the specified +variable (e.g., \code{FLAG}) is added to the input dataset. This variable will +be the value provided in \code{true_value} for all selected records from \code{dataset_add} +which are merged into the input dataset, and the value provided in \code{false_value} otherwise. + +\emph{Permitted Values}: Variable name} + +\item{true_value}{True value + +The value for the specified variable \code{exist_flag}, applicable to +the first or last observation (depending on the mode) of each by group. + +Permitted Values: An atomic scalar} + +\item{false_value}{False value + +The value for the specified variable \code{exist_flag}, NOT applicable to +the first or last observation (depending on the mode) of each by group. + +Permitted Values: An atomic scalar} + \item{missing_values}{Values for non-matching observations For observations of the input dataset (\code{dataset}) which do not have a @@ -210,7 +238,7 @@ derive_vars_merged( mode = "last", new_vars = exprs(LASTWGT = VSSTRESN, LASTWGTU = VSSTRESU), filter_add = VSTESTCD == "WEIGHT", - match_flag = vsdatafl + exist_flag = vsdatafl ) \%>\% select(STUDYID, USUBJID, AGE, AGEU, LASTWGT, LASTWGTU, vsdatafl) diff --git a/man/derive_vars_merged_lookup.Rd b/man/derive_vars_merged_lookup.Rd index 80761151a2..3024d10083 100644 --- a/man/derive_vars_merged_lookup.Rd +++ b/man/derive_vars_merged_lookup.Rd @@ -20,7 +20,7 @@ derive_vars_merged_lookup( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} argument are expected.} +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{dataset_add}{Lookup table diff --git a/man/derive_vars_period.Rd b/man/derive_vars_period.Rd index 05dd4dc48b..2d00f227b3 100644 --- a/man/derive_vars_period.Rd +++ b/man/derive_vars_period.Rd @@ -12,9 +12,9 @@ derive_vars_period( ) } \arguments{ -\item{dataset}{ADSL dataset +\item{dataset}{Input dataset -The variables specified by \code{subject_keys} are expected.} +The variables specified by the \code{subject_keys} argument(s) to be expected.} \item{dataset_ref}{Period reference dataset diff --git a/man/derive_vars_query.Rd b/man/derive_vars_query.Rd index 16a91bd87c..33452967df 100644 --- a/man/derive_vars_query.Rd +++ b/man/derive_vars_query.Rd @@ -7,7 +7,7 @@ derive_vars_query(dataset, dataset_queries) } \arguments{ -\item{dataset}{Input dataset.} +\item{dataset}{Input dataset} \item{dataset_queries}{A dataset containing required columns \code{PREFIX}, \code{GRPNAME}, \code{SRCVAR}, \code{TERMNAME}, \code{TERMID}, and optional columns diff --git a/man/derive_vars_transposed.Rd b/man/derive_vars_transposed.Rd index effa25f80c..8195dd1166 100644 --- a/man/derive_vars_transposed.Rd +++ b/man/derive_vars_transposed.Rd @@ -16,7 +16,7 @@ derive_vars_transposed( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} parameter are required} +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{dataset_merge}{Dataset to transpose and merge diff --git a/man/extract_duplicate_records.Rd b/man/extract_duplicate_records.Rd index 6c29348703..3a1f4213e9 100644 --- a/man/extract_duplicate_records.Rd +++ b/man/extract_duplicate_records.Rd @@ -7,7 +7,9 @@ extract_duplicate_records(dataset, by_vars) } \arguments{ -\item{dataset}{A data frame} +\item{dataset}{Input dataset + +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{by_vars}{A list of expressions created using \code{exprs()} identifying groups of records in which to look for duplicates} diff --git a/man/filter_exist.Rd b/man/filter_exist.Rd index 20697b3916..cc176c23ce 100644 --- a/man/filter_exist.Rd +++ b/man/filter_exist.Rd @@ -9,7 +9,7 @@ filter_exist(dataset, dataset_add, by_vars, filter_add = NULL) \arguments{ \item{dataset}{Input dataset -The variables specified in the \code{by_vars} parameter are expected in this dataset.} +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{dataset_add}{Source dataset diff --git a/man/filter_extreme.Rd b/man/filter_extreme.Rd index 6842ff97e6..0e7d5bbc3b 100644 --- a/man/filter_extreme.Rd +++ b/man/filter_extreme.Rd @@ -9,8 +9,7 @@ filter_extreme(dataset, by_vars = NULL, order, mode, check_type = "warning") \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{order} and the \code{by_vars} parameter are -expected.} +The variables specified by the \code{by_vars} and \code{order} argument(s) to be expected.} \item{by_vars}{Grouping variables diff --git a/man/filter_joined.Rd b/man/filter_joined.Rd index 8361945017..09c6b5f660 100644 --- a/man/filter_joined.Rd +++ b/man/filter_joined.Rd @@ -19,8 +19,7 @@ filter_joined( \arguments{ \item{dataset}{Input dataset -The variables specified for \code{by_vars}, \code{join_vars}, and \code{order} are -expected.} +The variables specified by the \code{by_vars}, \code{order} and \code{join_vars} argument(s) to be expected.} \item{by_vars}{By variables diff --git a/man/filter_not_exist.Rd b/man/filter_not_exist.Rd index ae8c3d1f0c..57f0065aff 100644 --- a/man/filter_not_exist.Rd +++ b/man/filter_not_exist.Rd @@ -9,7 +9,7 @@ filter_not_exist(dataset, dataset_add, by_vars, filter_add = NULL) \arguments{ \item{dataset}{Input dataset -The variables specified in the \code{by_vars} parameter are expected in this dataset.} +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{dataset_add}{Source dataset diff --git a/man/filter_relative.Rd b/man/filter_relative.Rd index 220ce39caf..dd0f532da7 100644 --- a/man/filter_relative.Rd +++ b/man/filter_relative.Rd @@ -19,8 +19,7 @@ filter_relative( \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{order} and the \code{by_vars} parameter are -expected.} +The variables specified by the \code{by_vars} and \code{order} argument(s) to be expected.} \item{by_vars}{Grouping variables diff --git a/man/get_hori_data.Rd b/man/get_hori_data.Rd index e416b453b9..9be797f41b 100644 --- a/man/get_hori_data.Rd +++ b/man/get_hori_data.Rd @@ -7,7 +7,9 @@ get_hori_data(dataset, by_vars, parameters, set_values_to, filter) } \arguments{ -\item{dataset}{Input dataset} +\item{dataset}{Input dataset + +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{by_vars}{By variables} diff --git a/man/get_summary_records.Rd b/man/get_summary_records.Rd index ba0f3786d9..e63f9d477e 100644 --- a/man/get_summary_records.Rd +++ b/man/get_summary_records.Rd @@ -10,11 +10,13 @@ get_summary_records( filter = NULL, analysis_var, summary_fun, - set_values_to = NULL + set_values_to ) } \arguments{ -\item{dataset}{A data frame.} +\item{dataset}{Input dataset + +The variables specified by the \code{by_vars} and \code{analysis_var} argument(s) to be expected.} \item{by_vars}{Variables to consider for generation of groupwise summary records. Providing the names of variables in \code{\link[=exprs]{exprs()}} will create a @@ -33,23 +35,39 @@ values greater than mean of AVAL with in \code{by_vars}. than 2. }} -\item{analysis_var}{Analysis variable.} +\item{analysis_var}{Analysis variable. + +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{set_values_to} instead.} \item{summary_fun}{Function that takes as an input the \code{analysis_var} and performs the calculation. + +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{set_values_to} instead. + This can include built-in functions as well as user defined functions, for example \code{mean} or \code{function(x) mean(x, na.rm = TRUE)}.} -\item{set_values_to}{A list of variable name-value pairs. Use this argument -if you need to change the values of any newly derived records. +\item{set_values_to}{Variables to be set + +The specified variables are set to the specified values for the new +observations. -Set a list of variables to some specified value for the new observation(s) +Set a list of variables to some specified value for the new records \itemize{ \item LHS refer to a variable. -\item RHS refers to the values to set to the variable. This can be a string, a symbol, a numeric -value, an expression or NA. -(e.g. \code{exprs(PARAMCD = "TDOSE",PARCAT1 = "OVERALL")}). -}} +\item RHS refers to the values to set to the variable. This can be a string, a +symbol, a numeric value, an expression or NA. If summary functions are +used, the values are summarized by the variables specified for \code{by_vars}. +} + +For example: + +\if{html}{\out{
}}\preformatted{ set_values_to = exprs( + AVAL = sum(AVAL), + PARAMCD = "TDOSE", + PARCAT1 = "OVERALL" + ) +}\if{html}{\out{
}}} } \value{ A data frame of derived records. @@ -67,82 +85,68 @@ see the \code{derive_summary_records()} function. } \examples{ library(tibble) -library(dplyr, warn.conflicts = FALSE) adeg <- tribble( - ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, - "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, "", - "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, "", - "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, "", - "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:45", 384, "Placebo", - "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", - "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", - "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:45", 385, "Placebo", - "XYZ-1001", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", - "XYZ-1001", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", - "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, "", - "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, "", - "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, "", - "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:50", 401, "Active 20mg", - "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", - "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", - "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:50", 412, "Active 20mg", - "XYZ-1002", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", - "XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg", + ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, + "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_, + "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, NA_character_, + "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, NA_character_, + "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:45", 384, "Placebo", + "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", + "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", + "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:45", 385, "Placebo", + "XYZ-1001", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", + "XYZ-1001", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", + "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, NA_character_, + "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, NA_character_, + "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, NA_character_, + "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:50", 401, "Active 20mg", + "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", + "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", + "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:50", 412, "Active 20mg", + "XYZ-1002", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", + "XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg" ) # Summarize the average of the triplicate ECG interval values (AVAL) get_summary_records( adeg, by_vars = exprs(USUBJID, PARAM, AVISIT), - analysis_var = AVAL, - summary_fun = function(x) mean(x, na.rm = TRUE), - set_values_to = exprs(DTYPE = "AVERAGE") -) - -advs <- tribble( - ~USUBJID, ~VSSEQ, ~PARAM, ~AVAL, ~VSSTRESU, ~VISIT, ~VSDTC, - "XYZ-001-001", 1164, "Weight", 99, "kg", "Screening", "2018-03-19", - "XYZ-001-001", 1165, "Weight", 101, "kg", "Run-In", "2018-03-26", - "XYZ-001-001", 1166, "Weight", 100, "kg", "Baseline", "2018-04-16", - "XYZ-001-001", 1167, "Weight", 94, "kg", "Week 24", "2018-09-30", - "XYZ-001-001", 1168, "Weight", 92, "kg", "Week 48", "2019-03-17", - "XYZ-001-001", 1169, "Weight", 95, "kg", "Week 52", "2019-04-14", + set_values_to = exprs( + AVAL = mean(AVAL, na.rm = TRUE), + DTYPE = "AVERAGE" + ) ) -# Set new values to any variable. Here, `DTYPE = MAXIMUM` refers to `max()` records -# and `DTYPE = AVERAGE` refers to `mean()` records. +# Derive more than one summary variable get_summary_records( - advs, - by_vars = exprs(USUBJID, PARAM), - analysis_var = AVAL, - summary_fun = max, - set_values_to = exprs(DTYPE = "MAXIMUM") -) \%>\% - get_summary_records( - by_vars = exprs(USUBJID, PARAM), - analysis_var = AVAL, - summary_fun = mean, - set_values_to = exprs(DTYPE = "AVERAGE") + adeg, + by_vars = exprs(USUBJID, PARAM, AVISIT), + set_values_to = exprs( + AVAL = mean(AVAL), + ASTDTM = min(convert_dtc_to_dtm(EGDTC)), + AENDTM = max(convert_dtc_to_dtm(EGDTC)), + DTYPE = "AVERAGE" ) +) # Sample ADEG dataset with triplicate record for only AVISIT = 'Baseline' adeg <- tribble( - ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, - "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, "", - "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, "", - "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, "", - "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", - "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", - "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", - "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", - "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, "", - "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, "", - "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, "", - "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", - "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", - "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", - "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg", + ~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA, + "XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_, + "XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, NA_character_, + "XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, NA_character_, + "XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo", + "XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo", + "XYZ-1001", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo", + "XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo", + "XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, NA_character_, + "XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, NA_character_, + "XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, NA_character_, + "XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg", + "XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg", + "XYZ-1002", 6, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg", + "XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg" ) # Compute the average of AVAL only if there are more than 2 records within the @@ -151,13 +155,14 @@ get_summary_records( adeg, by_vars = exprs(USUBJID, PARAM, AVISIT), filter = n() > 2, - analysis_var = AVAL, - summary_fun = function(x) mean(x, na.rm = TRUE), - set_values_to = exprs(DTYPE = "AVERAGE") + set_values_to = exprs( + AVAL = mean(AVAL, na.rm = TRUE), + DTYPE = "AVERAGE" + ) ) } \seealso{ -\code{derive_summary_records()} +\code{\link[=derive_summary_records]{derive_summary_records()}}, \code{\link[=derive_var_merged_summary]{derive_var_merged_summary()}} General Derivation Functions for all ADaMs that returns variable appended to dataset: \code{\link{derive_var_extreme_flag}()}, diff --git a/man/restrict_derivation.Rd b/man/restrict_derivation.Rd index 399717f856..9afa13a8fd 100644 --- a/man/restrict_derivation.Rd +++ b/man/restrict_derivation.Rd @@ -15,10 +15,7 @@ A function that performs a specific derivation is expected. A derivation adds variables or observations to a dataset. The first argument of a derivation must expect a dataset and the derivation must return a dataset. The function must provide the \code{dataset} argument and all arguments -specified in the \code{params()} objects passed to the \code{arg} argument. - -Please note that it is not possible to specify \code{{dplyr}} -functions like \code{mutate()} or \code{summarize()}.} +specified in the \code{params()} objects passed to the \code{arg} argument.} \item{args}{Arguments of the derivation diff --git a/man/signal_duplicate_records.Rd b/man/signal_duplicate_records.Rd index 1076de7329..04e06cdb66 100644 --- a/man/signal_duplicate_records.Rd +++ b/man/signal_duplicate_records.Rd @@ -13,7 +13,9 @@ signal_duplicate_records( ) } \arguments{ -\item{dataset}{A data frame} +\item{dataset}{Input dataset + +The variables specified by the \code{by_vars} argument(s) to be expected.} \item{by_vars}{A list of expressions created using \code{exprs()} identifying groups of records in which to look for duplicates} diff --git a/renv/profiles/4.1/renv/settings.json b/renv/profiles/4.1/renv/settings.json index 4922677e15..0c8943c5c8 100644 --- a/renv/profiles/4.1/renv/settings.json +++ b/renv/profiles/4.1/renv/settings.json @@ -4,7 +4,6 @@ "ignored.packages": [ "admiral", "admiraldev", - "admiral.test", "admiralci", "pharmaversesdtm" ], diff --git a/renv/profiles/4.2/renv/settings.json b/renv/profiles/4.2/renv/settings.json index 4922677e15..0c8943c5c8 100644 --- a/renv/profiles/4.2/renv/settings.json +++ b/renv/profiles/4.2/renv/settings.json @@ -4,7 +4,6 @@ "ignored.packages": [ "admiral", "admiraldev", - "admiral.test", "admiralci", "pharmaversesdtm" ], diff --git a/renv/profiles/4.3/renv/settings.json b/renv/profiles/4.3/renv/settings.json index 4922677e15..0c8943c5c8 100644 --- a/renv/profiles/4.3/renv/settings.json +++ b/renv/profiles/4.3/renv/settings.json @@ -4,7 +4,6 @@ "ignored.packages": [ "admiral", "admiraldev", - "admiral.test", "admiralci", "pharmaversesdtm" ], diff --git a/renv/settings.json b/renv/settings.json index 3462f3b093..0c8943c5c8 100644 --- a/renv/settings.json +++ b/renv/settings.json @@ -4,8 +4,8 @@ "ignored.packages": [ "admiral", "admiraldev", - "admiral.test", - "admiralci" + "admiralci", + "pharmaversesdtm" ], "package.dependency.fields": [ "Imports", diff --git a/tests/testthat/test-call_derivation.R b/tests/testthat/test-call_derivation.R index 3fedf501fc..c5e9e10abc 100644 --- a/tests/testthat/test-call_derivation.R +++ b/tests/testthat/test-call_derivation.R @@ -6,23 +6,26 @@ test_that("call_derivation Test 1: Test that call_derivation generates expected expected_output <- input %>% derive_summary_records( by_vars = exprs(USUBJID, VSTESTCD), - analysis_var = VSSTRESN, - summary_fun = function(x) mean(x, na.rm = TRUE), - set_values_to = exprs(DTYPE = "AVERAGE"), + set_values_to = exprs( + VSSTRESN = mean(VSSTRESN, na.rm = TRUE), + DTYPE = "AVERAGE" + ), filter = dplyr::n() >= 2L ) %>% derive_summary_records( by_vars = exprs(USUBJID, VSTESTCD), - analysis_var = VSSTRESN, - summary_fun = function(x) max(x, na.rm = TRUE), - set_values_to = exprs(DTYPE = "MAXIMUM"), + set_values_to = exprs( + VSSTRESN = max(VSSTRESN, na.rm = TRUE), + DTYPE = "MAXIMUM" + ), filter = dplyr::n() >= 2L ) %>% derive_summary_records( by_vars = exprs(USUBJID, VSTESTCD), - analysis_var = VSSTRESN, - summary_fun = function(x) min(x, na.rm = TRUE), - set_values_to = exprs(DTYPE = "MINIMUM"), + set_values_to = exprs( + VSSTRESN = min(VSSTRESN, na.rm = TRUE), + DTYPE = "MINIMUM" + ), filter = dplyr::n() >= 2L ) @@ -31,20 +34,25 @@ test_that("call_derivation Test 1: Test that call_derivation generates expected derivation = derive_summary_records, variable_params = list( params( - summary_fun = function(x) mean(x, na.rm = TRUE), - set_values_to = exprs(DTYPE = "AVERAGE") + set_values_to = exprs( + VSSTRESN = mean(VSSTRESN, na.rm = TRUE), + DTYPE = "AVERAGE" + ) ), params( - summary_fun = function(x) max(x, na.rm = TRUE), - set_values_to = exprs(DTYPE = "MAXIMUM") + set_values_to = exprs( + VSSTRESN = max(VSSTRESN, na.rm = TRUE), + DTYPE = "MAXIMUM" + ) ), params( - summary_fun = function(x) min(x, na.rm = TRUE), - set_values_to = exprs(DTYPE = "MINIMUM") + set_values_to = exprs( + VSSTRESN = min(VSSTRESN, na.rm = TRUE), + DTYPE = "MINIMUM" + ) ) ), by_vars = exprs(USUBJID, VSTESTCD), - analysis_var = VSSTRESN, filter = dplyr::n() >= 2L ) diff --git a/tests/testthat/test-compute_kidney.R b/tests/testthat/test-compute_kidney.R index f5e1dedc1f..b0739f11e9 100644 --- a/tests/testthat/test-compute_kidney.R +++ b/tests/testthat/test-compute_kidney.R @@ -100,12 +100,13 @@ test_that("compute_egfr Test 7: CKD-EPI calculated on input data", { ) }) -## Test 8: Deprecate wt ---- +## Test 8: 'wt' argument deprecation warning ---- test_that("compute_egfr Test 8: 'wt' argument deprecation warning", { # expect deprecation warning - expect_warning( + expect_error( compute_egfr( creat = 1.09, creatu = "mg/dL", age = 55, sex = "M", wt = 90, method = "CRCL" - ) + ), + class = "lifecycle_error_deprecated" ) }) diff --git a/tests/testthat/test-compute_scale.R b/tests/testthat/test-compute_scale.R index b4bb4dc6bb..afb20f819f 100644 --- a/tests/testthat/test-compute_scale.R +++ b/tests/testthat/test-compute_scale.R @@ -97,11 +97,10 @@ test_that("compute_scale Test 5: compute_scale() works as expected within input, by_vars = exprs(STUDYID, USUBJID, AVISIT, AVISITN), filter = (PARAMCD %in% c("ITEM1", "ITEM2", "ITEM3")), - analysis_var = AVAL, - summary_fun = function(x) { - compute_scale(x, c(1, 5), c(0, 100), flip_direction = TRUE, min_n = 3) - }, - set_values_to = exprs(PARAMCD = "ITEMAVG") + set_values_to = exprs( + AVAL = compute_scale(AVAL, c(1, 5), c(0, 100), flip_direction = TRUE, min_n = 3), + PARAMCD = "ITEMAVG" + ) ), expected_output ) diff --git a/tests/testthat/test-derive_extreme_records.R b/tests/testthat/test-derive_extreme_records.R index e5ee12a87a..53d34bc804 100644 --- a/tests/testthat/test-derive_extreme_records.R +++ b/tests/testthat/test-derive_extreme_records.R @@ -89,9 +89,9 @@ test_that("derive_extreme_records Test 2: derive first PD date", { adrs, tibble::tribble( ~USUBJID, ~ADT, ~AVALC, - "1", ymd(""), "N", + "1", ymd(""), NA_character_, "2", ymd("2021-07-16"), "Y", - "3", ymd(""), "N" + "3", ymd(""), NA_character_ ) %>% mutate( STUDYID = "XX1234", @@ -299,71 +299,8 @@ test_that("derive_extreme_records Test 5: latest evaluable tumor assessment date ) }) -## Test 6: warning if filter argument is used ---- -test_that("derive_extreme_records Test 6: warning if filter argument is used", { - adsl <- tibble::tribble( - ~USUBJID, - "1", - "2", - "3" - ) %>% - mutate(STUDYID = "XX1234") - - adrs <- tibble::tribble( - ~USUBJID, ~ADTC, ~AVALC, ~PARAMCD, - "1", "2020-01-02", "PR", "OVR", - "1", "2020-02-01", "CR", "OVR", - "1", "2020-03-01", "NE", "OVR", - "1", "2020-04-01", "SD", "OVR", - "2", "2021-06-15", "SD", "OVR", - "2", "2021-07-16", "SD", "OVR", - "2", "2021-09-14", "NE", "OVR", - "3", "2021-08-03", "NE", "OVR", - ) %>% - mutate( - STUDYID = "XX1234", - ADT = ymd(ADTC) - ) %>% - select(-ADTC) - - actual <- derive_extreme_records( - adrs, - dataset_ref = adsl, - dataset_add = adrs, - by_vars = exprs(USUBJID), - filter_add = PARAMCD == "OVR" & AVALC == "PD", - exist_flag = AVALC, - order = exprs(ADT), - mode = "first", - set_values_to = exprs( - PARAMCD = "PD", - ANL01FL = "Y", - ADT = ADT - ) - ) - - expect_error( - derive_extreme_records( - adrs, - dataset_ref = adsl, - dataset_add = adrs, - by_vars = exprs(USUBJID), - filter = PARAMCD == "OVR" & AVALC == "PD", - exist_flag = AVALC, - order = exprs(ADT), - mode = "first", - set_values_to = exprs( - PARAMCD = "PD", - ANL01FL = "Y", - ADT = ADT - ) - ), - class = "lifecycle_error_deprecated" - ) -}) - -## Test 7: error if no input data ---- -test_that("derive_extreme_records Test 7: error if no input data", { +## Test 6: error if no input data ---- +test_that("derive_extreme_records Test 6: error if no input data", { expect_error( derive_extreme_records( set_values_to = exprs(PARAMCD = "HELLO") @@ -377,8 +314,8 @@ test_that("derive_extreme_records Test 7: error if no input data", { ) }) -## Test 8: keep vars in `keep_source_vars` in the new records ---- -test_that("derive_extreme_records Test 8: keep vars in `keep_source_vars` in the new records", { +## Test 7: keep vars in `keep_source_vars` in the new records ---- +test_that("derive_extreme_records Test 7: keep vars in `keep_source_vars` in the new records", { input <- tibble::tribble( ~USUBJID, ~AVISITN, ~AVAL, ~LBSEQ, 1, 1, 12, 1, @@ -416,8 +353,8 @@ test_that("derive_extreme_records Test 8: keep vars in `keep_source_vars` in the ) }) -## Test 9: keep all vars in the new records when `keep_source_vars` is 'exprs(everything())' ---- -test_that("derive_extreme_records Test 9: keep all vars in the new records when `keep_source_vars` is 'exprs(everything())'", { # nolint +## Test 8: keep all vars in the new records when `keep_source_vars` is 'exprs(everything())' ---- +test_that("derive_extreme_records Test 8: keep all vars in the new records when `keep_source_vars` is 'exprs(everything())'", { # nolint input <- tibble::tribble( ~USUBJID, ~AVISITN, ~AVAL, ~LBSEQ, 1, 1, 12, 1, diff --git a/tests/testthat/test-derive_joined.R b/tests/testthat/test-derive_joined.R index eeb1afcc23..f52587cef7 100644 --- a/tests/testthat/test-derive_joined.R +++ b/tests/testthat/test-derive_joined.R @@ -333,3 +333,37 @@ test_that("derive_vars_joined Test 10: order vars are selected properly in funct keys = c("day", "val", "first_val") ) }) + +## Test 11: Ensure exist_flag, true/false value arguments work ---- +test_that("derive_vars_joined Test 11: Ensure exist_flag, true/false value arguments work", { + expected <- tibble::tribble( + ~USUBJID, ~ADY, ~AVISIT, ~AWLO, ~AWHI, ~flag, + "1", -2, "BASELINE", -30, 1, "Yes", + "1", 3, "WEEK 1", 2, 7, "Yes", + "1", 24, "WEEK 4", 23, 30, "Yes", + "2", NA, NA, NA, NA, "No" + ) + + windows <- tibble::tribble( + ~AVISIT, ~AWLO, ~AWHI, + "BASELINE", -30, 1, + "WEEK 1", 2, 7, + "WEEK 2", 8, 15, + "WEEK 3", 16, 22, + "WEEK 4", 23, 30 + ) + + expect_dfs_equal( + base = expected, + comp = derive_vars_joined( + select(expected, USUBJID, ADY), + dataset_add = windows, + join_vars = exprs(AWHI, AWLO), + filter_join = AWLO <= ADY & ADY <= AWHI, + exist_flag = flag, + true_value = "Yes", + false_value = "No" + ), + keys = c("USUBJID", "ADY") + ) +}) diff --git a/tests/testthat/test-derive_merged.R b/tests/testthat/test-derive_merged.R index ef069a52c8..c9bf4d8ad4 100644 --- a/tests/testthat/test-derive_merged.R +++ b/tests/testthat/test-derive_merged.R @@ -103,11 +103,11 @@ test_that("derive_vars_merged Test 3: merge last value and flag matched by group by_vars = exprs(STUDYID, USUBJID), new_vars = exprs(WEIGHTBL = AVAL), mode = "last", - match_flag = matched + exist_flag = matched ) expected <- adsl %>% mutate( WEIGHTBL = c(68, 88, 55, NA), - matched = c(TRUE, TRUE, TRUE, NA) + matched = c("Y", "Y", "Y", NA_character_) ) expect_dfs_equal( @@ -117,8 +117,32 @@ test_that("derive_vars_merged Test 3: merge last value and flag matched by group ) }) -## Test 4: error if variable in both datasets ---- -test_that("derive_vars_merged Test 4: error if variable in both datasets", { +## Test 4: merge last value and flag matched by groups ---- +test_that("derive_vars_merged Test 4: merge last value and flag matched by groups", { + actual <- derive_vars_merged(adsl, + dataset_add = advs, + order = exprs(AVAL), + by_vars = exprs(STUDYID, USUBJID), + new_vars = exprs(WEIGHTBL = AVAL), + mode = "last", + exist_flag = matched, + true_value = "Y", + false_value = "N" + ) + expected <- adsl %>% mutate( + WEIGHTBL = c(68, 88, 55, NA), + matched = c("Y", "Y", "Y", "N") + ) + + expect_dfs_equal( + base = expected, + compare = actual, + keys = c("USUBJID") + ) +}) + +## Test 5: error if variable in both datasets ---- +test_that("derive_vars_merged Test 5: error if variable in both datasets", { expect_error( derive_vars_merged(advs, dataset_add = adsl, @@ -128,8 +152,8 @@ test_that("derive_vars_merged Test 4: error if variable in both datasets", { ) }) -## Test 5: by_vars with rename ---- -test_that("derive_vars_merged Test 5: by_vars with rename", { +## Test 6: by_vars with rename ---- +test_that("derive_vars_merged Test 6: by_vars with rename", { actual <- derive_vars_merged(advs, dataset_add = adsl1, by_vars = exprs(STUDYID, USUBJID = ID), @@ -146,8 +170,8 @@ test_that("derive_vars_merged Test 5: by_vars with rename", { ) }) -## Test 6: expressions for new_vars and missing_values ---- -test_that("derive_vars_merged Test 6: expressions for new_vars and missing_values", { +## Test 7: expressions for new_vars and missing_values ---- +test_that("derive_vars_merged Test 7: expressions for new_vars and missing_values", { actual <- derive_vars_merged( adsl, dataset_add = advs, @@ -169,8 +193,38 @@ test_that("derive_vars_merged Test 6: expressions for new_vars and missing_value ) }) -## Test 7: use new variables in filter_add and order ---- -test_that("derive_vars_merged Test 7: use new variables in filter_add and order", { + +## Test 8: Use of missing_values and exist_flags ---- +test_that("derive_vars_merged Test 8: Use of missing_values and exist_flags", { + actual <- derive_vars_merged( + adsl, + dataset_add = advs, + by_vars = exprs(USUBJID), + order = exprs(AVISIT), + new_vars = exprs(LASTVIS = str_to_upper(AVISIT)), + mode = "last", + missing_values = exprs(LASTVIS = "UNKNOWN"), + exist_flag = matched, + true_value = NA, + false_value = "No" + ) + + expected <- adsl %>% + mutate( + LASTVIS = c("WEEK 2", "BASELINE", "WEEK 4", "UNKNOWN"), + matched = c(NA, NA, NA, "No") + ) + + + expect_dfs_equal( + base = expected, + compare = actual, + keys = "USUBJID" + ) +}) + +## Test 9: use new variables in filter_add and order ---- +test_that("derive_vars_merged Test 9: use new variables in filter_add and order", { expected <- tibble::tribble( ~USUBJID, ~TRTSDT, ~TRTSSEQ, "ST42-1", "2020-12-14", 2, @@ -208,8 +262,8 @@ test_that("derive_vars_merged Test 7: use new variables in filter_add and order" ) }) -## Test 8: warning if not unique w.r.t the by variables and the order ---- -test_that("derive_vars_merged Test 8: warning if not unique w.r.t the by variables and the order", { +## Test 10: warning if not unique w.r.t the by variables and the order ---- +test_that("derive_vars_merged Test 10: warning if not unique w.r.t the by variables and the order", { # nolint expect_warning( actual <- derive_vars_merged(advs, dataset_add = adsl2, @@ -222,8 +276,8 @@ test_that("derive_vars_merged Test 8: warning if not unique w.r.t the by variabl ) }) -## Test 9: error if not unique w.r.t the by variables and the order ---- -test_that("derive_vars_merged Test 9: error if not unique w.r.t the by variables and the order", { +## Test 11: error if not unique w.r.t the by variables and the order ---- +test_that("derive_vars_merged Test 11: error if not unique w.r.t the by variables and the order", { expect_error( actual <- derive_vars_merged(advs, dataset_add = adsl2, @@ -237,8 +291,8 @@ test_that("derive_vars_merged Test 9: error if not unique w.r.t the by variables ) }) -## Test 10: error if variables in missing_values but not in new_vars ---- -test_that("derive_vars_merged Test 10: error if variables in missing_values but not in new_vars", { +## Test 12: error if variables in missing_values but not in new_vars ---- +test_that("derive_vars_merged Test 12: error if variables in missing_values but not in new_vars", { expect_error( derive_vars_merged( adsl, @@ -254,34 +308,23 @@ test_that("derive_vars_merged Test 10: error if variables in missing_values but ) }) -# derive_var_merged_cat ---- - -## Test 11: deprecation error ---- -test_that("derive_var_merged_cat Test 11: deprecation error", { - get_vscat <- function(x) { - if_else(x == "BASELINE", "BASELINE", "POST-BASELINE") - } - - expect_error( - derive_var_merged_cat( - adsl, +test_that("deprecation messaging for match_flag", { + expect_warning( + derive_vars_merged(adsl, dataset_add = advs, - by_vars = exprs(USUBJID), - new_var = LSTVSCAT, - source_var = AVISIT, - cat_fun = get_vscat, - order = exprs(AVISIT), + order = exprs(AVAL), + by_vars = exprs(STUDYID, USUBJID), + new_vars = exprs(WEIGHTBL = AVAL), mode = "last", - missing_value = "MISSING" + match_flag = matched ), - class = "lifecycle_error_deprecated" + class = "lifecycle_warning_deprecated" ) }) - # derive_var_merged_exist_flag ---- -## Test 12: merge existence flag ---- -test_that("derive_var_merged_exist_flag Test 12: merge existence flag", { +## Test 13: merge existence flag ---- +test_that("derive_var_merged_exist_flag Test 13: merge existence flag", { actual <- derive_var_merged_exist_flag( adsl, dataset_add = advs, @@ -301,8 +344,8 @@ test_that("derive_var_merged_exist_flag Test 12: merge existence flag", { ) }) -## Test 13: by_vars with rename ---- -test_that("derive_var_merged_exist_flag Test 13: by_vars with rename", { +## Test 14: by_vars with rename ---- +test_that("derive_var_merged_exist_flag Test 14: by_vars with rename", { actual <- derive_var_merged_exist_flag( adsl, dataset_add = advs1, @@ -322,25 +365,6 @@ test_that("derive_var_merged_exist_flag Test 13: by_vars with rename", { ) }) -# derive_var_merged_character ---- - -## Test 14: deprecation error ---- -test_that("derive_var_merged_character Test 14: deprecation error", { - expect_error( - derive_var_merged_character( - adsl, - dataset_add = advs, - by_vars = exprs(USUBJID), - order = exprs(AVISIT), - new_var = LASTVIS, - source_var = AVISIT, - mode = "last" - ), - class = "lifecycle_error_deprecated" - ) -}) - - # derive_vars_merged_lookup ---- ## Test 15: merge lookup table ---- test_that("derive_vars_merged_lookup Test 15: merge lookup table", { @@ -513,9 +537,7 @@ test_that("derive_var_merged_summary Test 19: dataset == dataset_add, no filter" adbds, dataset_add = adbds, by_vars = exprs(AVISIT), - new_var = MEANVIS, - analysis_var = AVAL, - summary_fun = function(x) mean(x, na.rm = TRUE) + new_vars = exprs(MEANVIS = mean(AVAL, na.rm = TRUE)) ), keys = c("AVISIT", "ASEQ") ) @@ -546,10 +568,8 @@ test_that("derive_var_merged_summary Test 20: dataset != dataset_add, filter", { adsl, dataset_add = adbds, by_vars = exprs(USUBJID), - new_var = MEANPBL, - filter_add = ADY > 0, - analysis_var = AVAL, - summary_fun = function(x) mean(x, na.rm = TRUE) + new_vars = exprs(MEANPBL = mean(AVAL, na.rm = TRUE)), + filter_add = ADY > 0 ), keys = c("USUBJID") ) @@ -577,10 +597,42 @@ test_that("derive_var_merged_summary Test 21: by_vars with rename", { adbds, dataset_add = adbds1, by_vars = exprs(AVISIT = VISIT), + new_vars = exprs(MEANVIS = mean(AVAL, na.rm = TRUE)) + ), + keys = c("AVISIT", "ASEQ") + ) +}) + +## Test 22: deprecation warning ---- +test_that("derive_var_merged_summary Test 22: deprecation warning", { + expected <- tibble::tribble( + ~AVISIT, ~ASEQ, ~AVAL, ~MEANVIS, + "WEEK 1", 1, 10, 10, + "WEEK 1", 2, NA, 10, + "WEEK 2", 3, NA, NA, + "WEEK 3", 4, 42, 42, + "WEEK 4", 5, 12, 13, + "WEEK 4", 6, 12, 13, + "WEEK 4", 7, 15, 13 + ) + + adbds <- select(expected, -MEANVIS) + + expect_warning( + actual <- derive_var_merged_summary( + adbds, + dataset_add = adbds, + by_vars = exprs(AVISIT), new_var = MEANVIS, analysis_var = AVAL, summary_fun = function(x) mean(x, na.rm = TRUE) ), + class = "lifecycle_warning_deprecated" + ) + + expect_dfs_equal( + base = expected, + compare = actual, keys = c("AVISIT", "ASEQ") ) }) diff --git a/tests/testthat/test-derive_param_computed.R b/tests/testthat/test-derive_param_computed.R index 165bddfeec..5412ce6de8 100644 --- a/tests/testthat/test-derive_param_computed.R +++ b/tests/testthat/test-derive_param_computed.R @@ -353,7 +353,7 @@ test_that("derive_param_computed Test 8: no new observations if a constant param ) }) -## Test 9: compute multiple variables ---- +## Test 9: compute multiple variables, keep_nas ---- test_that("derive_param_computed Test 9: compute multiple variables, keep_nas", { adlb_tbilialk <- tibble::tribble( ~USUBJID, ~PARAMCD, ~AVALC, ~ADTM, ~ADTF, @@ -429,7 +429,7 @@ test_that("derive_param_computed Test 10: deprecation warning if analysis_value select(-AVAL.DIABP, -AVAL.SYSBP) expected_output <- bind_rows(input, new_obs) - expect_warning( + expect_error( derive_param_computed( input, parameters = exprs(SYSBP, DIABP), @@ -441,26 +441,7 @@ test_that("derive_param_computed Test 10: deprecation warning if analysis_value AVALU = "mmHg" ) ), - class = "lifecycle_warning_deprecated" - ) - - expect_dfs_equal( - suppress_warning( - derive_param_computed( - input, - parameters = exprs(SYSBP, DIABP), - by_vars = exprs(USUBJID, VISIT), - analysis_value = (AVAL.SYSBP + 2 * AVAL.DIABP) / 3, - set_values_to = exprs( - PARAMCD = "MAP", - PARAM = "Mean arterial pressure (mmHg)", - AVALU = "mmHg" - ) - ), - regexpr = "is deprecated" - ), - expected_output, - keys = c("USUBJID", "PARAMCD", "VISIT") + class = "lifecycle_error_deprecated" ) }) diff --git a/tests/testthat/test-derive_param_exist_flag.R b/tests/testthat/test-derive_param_exist_flag.R index a67093ec6e..bf5941bac8 100644 --- a/tests/testthat/test-derive_param_exist_flag.R +++ b/tests/testthat/test-derive_param_exist_flag.R @@ -65,8 +65,8 @@ test_that("derive_param_merged_exist_flag Test 1: derive parameter indicating PD -## derive_param_exist_flag Test 3: error is issued if paramter already exists in dataset ---- -test_that("derive_param_exist_flag Test 3: error is issued if paramter already exists in dataset", { +## Test 2: error is issued if paramter already exists in dataset ---- +test_that("derive_param_merged_exist_flag Test 2: error is issued if paramter already exists in dataset", { # nolint expect_error( derive_param_exist_flag( dataset = adrs, @@ -86,42 +86,3 @@ test_that("derive_param_exist_flag Test 3: error is issued if paramter already e fixed = TRUE ) }) - - - -## derive_param_merge_exist_flag Test 4: error for deprecated parameter ---- -test_that("derive_param_exist_flag Test 4: error for deprecated param `dataset_adsl`", { - expect_error( - derive_param_exist_flag( - dataset_adsl = adsl, - dataset_add = adrs, - filter_add = PARAMCD == "OVR", - condition = AVALC == "PD", - false_value = "N", - set_values_to = exprs( - PARAMCD = "PD", - ANL01FL = "Y" - ) - ), - class = "lifecycle_error_deprecated" - ) -}) - -## derive_param_merge_exist_flag Test 5: error for deprecated parameter ---- -test_that("derive_param_exist_flag Test 5: error for deprecated param `subject_keys`", { - expect_error( - derive_param_exist_flag( - dataset_ref = adsl, - dataset_add = adrs, - subject_keys = get_admiral_option("subject_keys"), - filter_add = PARAMCD == "OVR", - condition = AVALC == "PD", - false_value = "N", - set_values_to = exprs( - PARAMCD = "PD", - ANL01FL = "Y" - ) - ), - class = "lifecycle_error_deprecated" - ) -}) diff --git a/tests/testthat/test-derive_param_extreme_event.R b/tests/testthat/test-derive_param_extreme_event.R deleted file mode 100644 index c7bf98d854..0000000000 --- a/tests/testthat/test-derive_param_extreme_event.R +++ /dev/null @@ -1,51 +0,0 @@ -adsl <- tibble::tribble( - ~USUBJID, ~DTHDT, - "1", ymd("2022-05-13"), - "2", ymd(""), - "3", ymd("") -) %>% - mutate(STUDYID = "XX1234") - -adrs <- tibble::tribble( - ~USUBJID, ~ADTC, ~AVALC, ~PARAMCD, - "1", "2020-01-02", "PR", "OVR", - "1", "2020-02-01", "CR", "OVR", - "1", "2020-03-01", "CR", "OVR", - "1", "2020-04-01", "SD", "OVR", - "2", "2021-06-15", "SD", "OVR", - "2", "2021-07-16", "PD", "OVR", - "2", "2021-09-14", "PD", "OVR", - "1", "2020-01-02", "PR", "OVRF", - "1", "2020-02-01", "CR", "OVRF", - "1", "2020-03-01", "CR", "OVRF", - "1", "2020-04-01", "PD", "OVRF", - "2", "2021-06-15", "SD", "OVRF", - "2", "2021-07-16", "PD", "OVRF", - "2", "2021-09-14", "PD", "OVRF" -) %>% - mutate( - STUDYID = "XX1234", - ADT = ymd(ADTC) - ) %>% - select(-ADTC) - -# derive_param_extreme_event ---- -## Test 1: deprecation error if function is called ---- -test_that("derive_param_extreme_event Test 1: deprecation error if function is called", { - expect_error( - derive_param_extreme_event( - adrs, - dataset_adsl = adsl, - dataset_source = adrs, - filter_source = PARAMCD == "OVR" & AVALC == "PD", - new_var = AVALC, - order = exprs(ADT), - set_values_to = exprs( - PARAMCD = "PD", - ANL01FL = "Y", - ADT = ADT - ) - ), - class = "lifecycle_error_deprecated" - ) -}) diff --git a/tests/testthat/test-derive_summary_records.R b/tests/testthat/test-derive_summary_records.R index b61b82790f..c7b26c927e 100644 --- a/tests/testthat/test-derive_summary_records.R +++ b/tests/testthat/test-derive_summary_records.R @@ -1,142 +1,92 @@ ## Test 1: creates new record per group and groups are retained ---- test_that("derive_summary_records Test 1: creates new record per group and groups are retained", { - # group --> 4 - input <- tibble::tibble(x = rep(1:4, each = 4), y = rep(1:2, each = 8), z = runif(16)) + input <- tibble::tribble( + ~subj, ~visit, ~val, ~seq, + "1", 1, 10, 1, + "1", 1, 14, 2, + "1", 1, 9, 3, + "1", 2, 11, 4, + "2", 2, NA_real_, 1 + ) + actual_output <- input %>% derive_summary_records( - by_vars = exprs(x, y), - analysis_var = z, - summary_fun = mean + by_vars = exprs(subj, visit), + set_values_to = exprs( + val = mean(val), + seq = max(seq), + type = "AVERAGE" + ) ) - expect_equal(nrow(actual_output), nrow(input) + 4) - expect_equal(dplyr::group_vars(actual_output), dplyr::group_vars(input)) -}) - -## Test 2: `fns` as inlined ---- -test_that("derive_summary_records Test 2: `fns` as inlined", { - input <- tibble::tibble(x = rep(1:2, each = 2), y = 9:12, z = 101:104) - actual_output <- derive_summary_records( + expected_output <- bind_rows( input, - by_vars = exprs(x), - analysis_var = y, - summary_fun = function(x) mean(x, na.rm = TRUE) - ) - expected_output <- tibble::tibble( - x = rep(1:2, each = 3), - y = c(9:10, 9.5, 11:12, 11.5), - z = c(101:102, NA, 103:104, NA) + tibble::tribble( + ~subj, ~visit, ~val, ~seq, + "1", 1, 11, 3, + "1", 2, 11, 4, + "2", 2, NA_real_, 1 + ) %>% + mutate(type = "AVERAGE") ) - expect_dfs_equal(actual_output, expected_output, keys = c("x", "y", "z")) -}) - -## Test 3: set new value to a derived record ---- -test_that("derive_summary_records Test 3: set new value to a derived record", { - input <- tibble::tibble(x = rep(1:2, each = 2), y = 9:12) - actual_output <- derive_summary_records( - input, - by_vars = exprs(x), - analysis_var = y, - summary_fun = mean, - set_values_to = exprs(z = "MEAN") - ) - expected_output <- tibble::tibble( - x = rep(1:2, each = 3), - y = c(9:10, 9.5, 11:12, 11.5), - z = c(NA, NA, "MEAN", NA, NA, "MEAN") + expect_dfs_equal( + base = expected_output, + compare = actual_output, + keys = c("subj", "visit", "seq", "type") ) - - expect_dfs_equal(actual_output, expected_output, keys = c("x", "y", "z")) }) -## Test 4: check `set_values_to` mapping ---- -test_that("derive_summary_records Test 4: check `set_values_to` mapping", { - input <- tibble::tibble(x = rep(1:4, each = 4), y = rep(1:2, each = 8), z = runif(16)) - actual_output <- input %>% - derive_summary_records( - by_vars = exprs(x, y), - analysis_var = z, - summary_fun = mean, - set_values_to = exprs(d = "MEAN") - ) %>% - derive_summary_records( - by_vars = exprs(x, y), - analysis_var = z, - summary_fun = sum, - set_values_to = exprs(d = "SUM") - ) - tf <- rep(c(NA, "MEAN", "SUM"), c(16, 4, 4)) - - expect_equal(actual_output$d, tf) +## Test 2: Filter record within `by_vars` ---- +test_that("derive_summary_records Test 2: Filter record within `by_vars`", { + input <- tibble::tribble( + ~subj, ~visit, ~val, ~seq, + "1", 1, 10, 1, + "1", 1, 14, 2, + "1", 1, 9, 3, + "1", 2, 11, 4, + "2", 2, NA_real_, 1 + ) actual_output <- input %>% derive_summary_records( - by_vars = exprs(x, y), - analysis_var = z, - summary_fun = mean, - set_values_to = exprs(d = "MEAN", p1 = "PARAM1", p2 = "PARAM2") + by_vars = exprs(subj, visit), + filter = n() > 2, + set_values_to = exprs( + val = mean(val), + seq = max(seq), + type = "AVERAGE" + ) ) - tf <- rep(c(NA, "MEAN"), c(16, 4)) - tp1 <- rep(c(NA, "PARAM1"), c(16, 4)) - tp2 <- rep(c(NA, "PARAM2"), c(16, 4)) - - expect_equal(actual_output$d, tf) - expect_equal(actual_output$p1, tp1) - expect_equal(actual_output$p2, tp2) -}) - -## Test 5: Filter record within `by_vars` ---- -test_that("derive_summary_records Test 5: Filter record within `by_vars`", { - input <- tibble::tibble(x = c(rep(1:2, each = 2), 2), y = 9:13, z = c(1, 1, 2, 1, 1)) - actual_output <- derive_summary_records( + expected_output <- bind_rows( input, - by_vars = exprs(x), - analysis_var = y, - summary_fun = mean, - filter = n() > 2, - set_values_to = exprs(d = "MEAN") - ) - expected_output <- tibble::tibble( - x = c(rep(1, 2), rep(2, 4)), - y = c(9:13, 12), - z = c(1, 1, 2, 1, 1, NA), - d = c(rep(NA, 5), "MEAN") + tibble::tribble( + ~subj, ~visit, ~val, ~seq, + "1", 1, 11, 3, + ) %>% + mutate(type = "AVERAGE") ) - expect_dfs_equal(actual_output, expected_output, keys = c("x", "y", "z")) - - actual_output <- derive_summary_records( - input, - by_vars = exprs(x), - analysis_var = y, - summary_fun = mean, - filter = z == 1, - set_values_to = exprs(d = "MEAN") - ) - expected_output <- tibble::tibble( - x = c(rep(1, 3), rep(2, 4)), - y = c(9:10, 9.5, 11:13, 12.5), - z = c(1, 1, NA, 2, 1, 1, NA), - d = c(rep(NA, 2), "MEAN", rep(NA, 3), "MEAN") + expect_dfs_equal( + base = expected_output, + compare = actual_output, + keys = c("subj", "visit", "seq", "type") ) - - expect_dfs_equal(actual_output, expected_output, keys = c("x", "y", "z")) }) - -## Test 6: Errors ---- -test_that("derive_summary_records Test 6: Errors", { +## Test 3: Errors ---- +test_that("derive_summary_records Test 3: Errors", { input <- tibble::tibble(x = rep(1:4, each = 4), y = rep(1:2, each = 8), z = runif(16)) - # Is by_vars quosures/`exprs()` object? + # Is by_vars `exprs()` object? expect_error( derive_summary_records( input, by_vars = "x", - analysis_var = z, - summary_fun = mean + set_values_to = exprs( + z = mean(z) + ) ), regexp = "`arg` must be an object of class 'list' but is `\"x\"`" ) @@ -146,34 +96,50 @@ test_that("derive_summary_records Test 6: Errors", { derive_summary_records( input, by_vars = exprs(a), - analysis_var = z, - summary_fun = mean + set_values_to = exprs( + z = mean(z) + ) ), regexp = "Required variable `a` is missing" ) +}) - # summary_fun must be a single function - expect_error( - derive_summary_records( - input, - by_vars = exprs(x), - analysis_var = y, - summary_fun = list(mean, sum) - ), - regexp = "`summary_fun` must be an object of class 'function' but is a list" +## Test 4: deprecation warning for analysis_var and summary_fun ---- +test_that("derive_summary_records Test 4: deprecation warning for analysis_var and summary_fun", { + input <- tibble::tribble( + ~subj, ~visit, ~val, ~seq, + "1", 1, 10, 1, + "1", 1, 14, 2, + "1", 1, 9, 3, + "1", 2, 11, 4, + "2", 2, NA_real_, 1 ) - # summary_fun must be a single function - expect_error( - derive_summary_records( - input, - by_vars = exprs(x), - analysis_var = z, - summary_fun = ~mean - ), - regexp = paste( - "`summary_fun` must be an object of class 'function'", - "but is an object of class 'formula'" - ) + expected_output <- bind_rows( + input, + tibble::tribble( + ~subj, ~visit, ~val, + "1", 1, 11, + "1", 2, 11, + "2", 2, NA_real_ + ) %>% + mutate(type = "AVERAGE") + ) + + expect_warning( + actual_output <- input %>% + derive_summary_records( + by_vars = exprs(subj, visit), + analysis_var = val, + summary_fun = mean, + set_values_to = exprs(type = "AVERAGE") + ), + class = "lifecycle_warning_deprecated" + ) + + expect_dfs_equal( + base = expected_output, + compare = actual_output, + keys = c("subj", "visit", "seq", "type") ) }) diff --git a/tests/testthat/test-derive_var_basetype.R b/tests/testthat/test-derive_var_basetype.R deleted file mode 100644 index 0c27a79137..0000000000 --- a/tests/testthat/test-derive_var_basetype.R +++ /dev/null @@ -1,55 +0,0 @@ -# derive_var_basetype ---- -## Test 1: deprecation error if function is called ---- -test_that("derive_var_basetype Test 1: deprecation error if function is called", { - input <- tibble::tribble( - ~USUBJID, ~EPOCH, ~PARAMCD, ~ASEQ, ~AVAL, - "P01", "RUN-IN", "PARAM01", 1, 10.0, - "P01", "RUN-IN", "PARAM01", 2, 9.8, - "P01", "DOUBLE-BLIND", "PARAM01", 3, 9.2, - "P01", "DOUBLE-BLIND", "PARAM01", 4, 10.1, - "P01", "OPEN-LABEL", "PARAM01", 5, 10.4, - "P01", "OPEN-LABEL", "PARAM01", 6, 9.9, - "P02", "RUN-IN", "PARAM01", 1, 12.1, - "P02", "DOUBLE-BLIND", "PARAM01", 2, 10.2, - "P02", "DOUBLE-BLIND", "PARAM01", 3, 10.8, - "P02", "OPEN-LABEL", "PARAM01", 4, 11.4, - "P02", "OPEN-LABEL", "PARAM01", 5, 10.8 - ) - expect_output <- tibble::tribble( - ~USUBJID, ~EPOCH, ~PARAMCD, ~ASEQ, ~AVAL, ~BASETYPE, - "P01", "RUN-IN", "PARAM01", 1, 10.0, "RUN-IN", - "P01", "RUN-IN", "PARAM01", 2, 9.8, "RUN-IN", - "P01", "DOUBLE-BLIND", "PARAM01", 3, 9.2, "RUN-IN", - "P01", "DOUBLE-BLIND", "PARAM01", 4, 10.1, "RUN-IN", - "P01", "OPEN-LABEL", "PARAM01", 5, 10.4, "RUN-IN", - "P01", "OPEN-LABEL", "PARAM01", 6, 9.9, "RUN-IN", - "P01", "DOUBLE-BLIND", "PARAM01", 3, 9.2, "DOUBLE-BLIND", - "P01", "DOUBLE-BLIND", "PARAM01", 4, 10.1, "DOUBLE-BLIND", - "P01", "OPEN-LABEL", "PARAM01", 5, 10.4, "DOUBLE-BLIND", - "P01", "OPEN-LABEL", "PARAM01", 6, 9.9, "DOUBLE-BLIND", - "P01", "OPEN-LABEL", "PARAM01", 5, 10.4, "OPEN-LABEL", - "P01", "OPEN-LABEL", "PARAM01", 6, 9.9, "OPEN-LABEL", - "P02", "RUN-IN", "PARAM01", 1, 12.1, "RUN-IN", - "P02", "DOUBLE-BLIND", "PARAM01", 2, 10.2, "RUN-IN", - "P02", "DOUBLE-BLIND", "PARAM01", 3, 10.8, "RUN-IN", - "P02", "OPEN-LABEL", "PARAM01", 4, 11.4, "RUN-IN", - "P02", "OPEN-LABEL", "PARAM01", 5, 10.8, "RUN-IN", - "P02", "DOUBLE-BLIND", "PARAM01", 2, 10.2, "DOUBLE-BLIND", - "P02", "DOUBLE-BLIND", "PARAM01", 3, 10.8, "DOUBLE-BLIND", - "P02", "OPEN-LABEL", "PARAM01", 4, 11.4, "DOUBLE-BLIND", - "P02", "OPEN-LABEL", "PARAM01", 5, 10.8, "DOUBLE-BLIND", - "P02", "OPEN-LABEL", "PARAM01", 4, 11.4, "OPEN-LABEL", - "P02", "OPEN-LABEL", "PARAM01", 5, 10.8, "OPEN-LABEL", - ) - expect_error( - derive_var_basetype( - dataset = input, - basetypes = rlang::exprs( - "RUN-IN" = EPOCH %in% c("RUN-IN", "STABILIZATION", "DOUBLE-BLIND", "OPEN-LABEL"), - "DOUBLE-BLIND" = EPOCH %in% c("DOUBLE-BLIND", "OPEN-LABEL"), - "OPEN-LABEL" = EPOCH == "OPEN-LABEL" - ) - ), - class = "lifecycle_error_deprecated" - ) -}) diff --git a/tests/testthat/test-derive_var_dthcaus.R b/tests/testthat/test-derive_var_dthcaus.R index 32d811c593..5482326aa7 100644 --- a/tests/testthat/test-derive_var_dthcaus.R +++ b/tests/testthat/test-derive_var_dthcaus.R @@ -416,12 +416,13 @@ test_that("derive_var_dthcaus Test 8: `dataset` is sorted using the `order` para ## Test 9: returns a warning when traceability_vars is used ---- test_that("derive_var_dthcaus Test 9: returns a warning when traceability_vars is used", { + ae <- tibble::tribble( ~STUDYID, ~USUBJID, ~AESEQ, ~AEDECOD, ~AEOUT, ~AEDTHDTC, "TEST01", "PAT01", 12, "SUDDEN DEATH", "FATAL", "2021-04-04" ) - expect_warning( + expect_error( src_ae <- dthcaus_source( dataset_name = "ae", filter = AEOUT == "FATAL", @@ -434,7 +435,7 @@ test_that("derive_var_dthcaus Test 9: returns a warning when traceability_vars i DTHSEQ = AESEQ ) ), - class = "lifecycle_warning_deprecated" + class = "lifecycle_error_deprecated" ) }) diff --git a/tests/testthat/test-derive_var_extreme_date.R b/tests/testthat/test-derive_var_extreme_date.R index 98f99618f5..5529db4301 100644 --- a/tests/testthat/test-derive_var_extreme_date.R +++ b/tests/testthat/test-derive_var_extreme_date.R @@ -96,7 +96,7 @@ test_that("derive_var_extreme_dt Test 2: LSTALVDT is derived for Date class as w ) }) -## Test 3: NA dates are excluded ---- +## Test 3: `NA` dates are excluded ---- test_that("derive_var_extreme_dt Test 3: `NA` dates are excluded", { ae_end <- date_source( dataset_name = "ae", @@ -121,7 +121,7 @@ test_that("derive_var_extreme_dt Test 3: `NA` dates are excluded", { }) # derive_var_extreme_dtm ---- -## Test 4: LSTALVDTM and traceability variables are derived ---- +## Test 4: `LSTALVDTM` and traceability variables are derived ---- test_that("derive_var_extreme_dtm Test 4: `LSTALVDTM` and traceability variables are derived", { ae_start <- date_source( dataset_name = "ae", @@ -187,7 +187,7 @@ test_that("derive_var_extreme_dtm Test 4: `LSTALVDTM` and traceability variables ) }) -## Test 5: error is issued if DTC variable is specified ---- +## Test 5: error is issued if `--DTC` variable is specified ---- test_that("derive_var_extreme_dtm Test 5: error is issued if `--DTC` variable is specified", { ae_start <- date_source( dataset_name = "ae", @@ -211,9 +211,9 @@ test_that("derive_var_extreme_dtm Test 5: error is issued if `--DTC` variable is ) }) -## Test 6: Returns a warning when traceability_vars is assigned ---- +## Test 6: Returns a warning when traceability_vars is assigned ---- test_that("derive_var_extreme_dtm Test 6: Returns a warning when traceability_vars is assigned", { - expect_warning( + expect_error( ae_start <- date_source( dataset_name = "ae", date = convert_dtc_to_dtm(AESTDTC), @@ -223,6 +223,6 @@ test_that("derive_var_extreme_dtm Test 6: Returns a warning when traceability_va LALVVAR = "AESTDTC" ) ), - class = "lifecycle_warning_deprecated" + class = "lifecycle_error_deprecated" ) }) diff --git a/tests/testthat/test-derive_var_extreme_flag.R b/tests/testthat/test-derive_var_extreme_flag.R index c918c3d146..61062b7191 100644 --- a/tests/testthat/test-derive_var_extreme_flag.R +++ b/tests/testthat/test-derive_var_extreme_flag.R @@ -205,3 +205,34 @@ test_that("derive_var_extreme_flag Test 8: additional case for missing order var keys = c("USUBJID", "AVISITN", "AVAL") ) }) + + +## Test 9: changing true/false flag value works ---- +test_that("derive_var_extreme_flag Test 9: changing true/false flag value works", { + input <- tibble::tribble( + ~USUBJID, ~AVISITN, ~AVAL, + 1, 1, 12, + 1, 3, 9, + 2, 2, 42, + 3, 3, 14, + 3, 3, 10 + ) + + expected_output <- input %>% mutate(firstfl = c("Yes", "No", "Yes", "Yes", "No")) + + actual_output <- derive_var_extreme_flag( + input, + by_vars = exprs(USUBJID), + order = exprs(AVISITN, desc(AVAL)), + new_var = firstfl, + mode = "first", + true_value = "Yes", + false_value = "No" + ) + + expect_dfs_equal( + base = expected_output, + compare = actual_output, + keys = c("USUBJID", "AVISITN", "AVAL") + ) +}) diff --git a/tests/testthat/test-derive_var_last_dose_amt.R b/tests/testthat/test-derive_var_last_dose_amt.R deleted file mode 100644 index 1e4424bf6f..0000000000 --- a/tests/testthat/test-derive_var_last_dose_amt.R +++ /dev/null @@ -1,52 +0,0 @@ -input_ae <- tibble::tribble( - ~STUDYID, ~USUBJID, ~AESEQ, ~AESTDTC, - "my_study", "subject1", 1, "2020-01-02", - "my_study", "subject1", 2, "2020-08-31", - "my_study", "subject1", 3, "2020-10-10", - "my_study", "subject2", 1, "2019-05-15", - "my_study", "subject2", 2, "2020-02-20", - "my_study", "subject3", 1, "2020-03-02", - "my_study", "subject4", 1, "2020-11-02" -) %>% - mutate( - AESTDT = ymd(AESTDTC) - ) - -input_ex <- tibble::tribble( - ~STUDYID, ~USUBJID, ~EXSTDTC, ~EXENDTC, ~EXSEQ, ~EXDOSE, ~EXTRT, - "my_study", "subject1", "2020-01-01", "2020-01-01", 1, 10, "treatment", - "my_study", "subject1", "2020-08-29", "2020-08-29", 2, 10, "treatment", - "my_study", "subject1", "2020-09-02", "2020-09-02", 3, 10, "treatment", - "my_study", "subject1", "2020-10-20", "2020-10-20", 4, 10, "treatment", - "my_study", "subject2", "2019-05-25", "2019-05-25", 1, 0, "placebo", - "my_study", "subject2", "2020-01-20", "2020-01-20", 2, 0, "placebo", - "my_study", "subject3", "2020-03-15", "2020-03-15", 1, 10, "treatment" -) %>% - mutate( - EXSTDT = as.Date(EXSTDTC), - EXENDT = as.Date(EXENDTC) - ) - -# derive_var_last_dose_amt ---- -## Test 1: works as expected and returns an error message---- -test_that("derive_var_last_dose_amt Test 1: works as expected and returns an error message", { - expected_output <- mutate( - input_ae, - LDOSE = c(10, 10, 10, NA, 0, NA, NA) - ) - expect_error( - derive_var_last_dose_amt( - input_ae, - input_ex, - filter_ex = (EXDOSE > 0) | (EXDOSE == 0 & EXTRT == "placebo"), - by_vars = exprs(STUDYID, USUBJID), - dose_date = EXENDT, - analysis_date = AESTDT, - new_var = LDOSE, - dose_var = EXDOSE, - single_dose_condition = (EXSTDTC == EXENDTC), - traceability_vars = NULL - ), - class = "lifecycle_error_deprecated" - ) -}) diff --git a/tests/testthat/test-derive_var_last_dose_date.R b/tests/testthat/test-derive_var_last_dose_date.R deleted file mode 100644 index a755a02e79..0000000000 --- a/tests/testthat/test-derive_var_last_dose_date.R +++ /dev/null @@ -1,58 +0,0 @@ -input_ae <- tibble::tribble( - ~STUDYID, ~USUBJID, ~AESEQ, ~AESTDTC, - "my_study", "subject1", 1, "2020-01-02", - "my_study", "subject1", 2, "2020-08-31", - "my_study", "subject1", 3, "2020-10-10", - "my_study", "subject2", 1, "2019-05-15", - "my_study", "subject2", 2, "2020-02-20", - "my_study", "subject3", 1, "2020-03-02", - "my_study", "subject4", 1, "2020-11-02" -) %>% mutate( - AESTDT = ymd(AESTDTC) -) - -input_ex <- tibble::tribble( - ~STUDYID, ~USUBJID, ~EXSTDTC, ~EXENDTC, ~EXSEQ, ~EXDOSE, ~EXTRT, - "my_study", "subject1", "2020-01-01", "2020-01-01", 1, 10, "treatment", - "my_study", "subject1", "2020-08-29", "2020-08-29", 2, 10, "treatment", - "my_study", "subject1", "2020-09-02", "2020-09-02", 3, 10, "treatment", - "my_study", "subject1", "2020-10-20", "2020-10-20", 4, 10, "treatment", - "my_study", "subject2", "2019-05-25", "2019-05-25", 1, 0, "placebo", - "my_study", "subject2", "2020-01-20", "2020-01-20", 2, 0, "placebo", - "my_study", "subject3", "2020-03-15", "2020-03-15", 1, 10, "treatment" -) %>% - mutate(EXSTDT = as.Date(EXSTDTC), EXENDT = as.Date(EXENDTC)) - -# derive_var_last_dose_date ---- -## Test 1: returns an error when the function is called ---- -test_that("derive_var_last_dose_date Test 1: returns an error when the function is called", { - expected_output <- tibble::tribble( - ~STUDYID, ~USUBJID, ~AESEQ, ~AESTDTC, ~LDOSEDTM, - "my_study", "subject1", 1, "2020-01-02", "2020-01-01", - "my_study", "subject1", 2, "2020-08-31", "2020-08-29", - "my_study", "subject1", 3, "2020-10-10", "2020-09-02", - "my_study", "subject2", 1, "2019-05-15", NA_character_, - "my_study", "subject2", 2, "2020-02-20", "2020-01-20", - "my_study", "subject3", 1, "2020-03-02", NA_character_, - "my_study", "subject4", 1, "2020-11-02", NA_character_ - ) %>% - mutate( - LDOSEDTM = as.Date(LDOSEDTM), - AESTDT = ymd(AESTDTC) - ) - expect_error( - derive_var_last_dose_date( - input_ae, - input_ex, - filter_ex = (EXDOSE > 0) | (EXDOSE == 0 & EXTRT == "placebo"), - by_vars = exprs(STUDYID, USUBJID), - dose_date = EXENDT, - analysis_date = AESTDT, - new_var = LDOSEDTM, - single_dose_condition = (EXSTDTC == EXENDTC), - output_datetime = FALSE, - traceability_vars = NULL - ), - class = "lifecycle_error_deprecated" - ) -}) diff --git a/tests/testthat/test-derive_var_last_dose_grp.R b/tests/testthat/test-derive_var_last_dose_grp.R deleted file mode 100644 index 6e930756e1..0000000000 --- a/tests/testthat/test-derive_var_last_dose_grp.R +++ /dev/null @@ -1,58 +0,0 @@ -input_ae <- tibble::tribble( - ~STUDYID, ~USUBJID, ~AESEQ, ~AESTDTC, - "my_study", "subject1", 1, "2020-01-02", - "my_study", "subject1", 2, "2020-08-31", - "my_study", "subject1", 3, "2020-10-10", - "my_study", "subject2", 1, "2019-05-15", - "my_study", "subject2", 2, "2020-02-20", - "my_study", "subject3", 1, "2020-03-02", - "my_study", "subject4", 1, "2020-11-02" -) %>% mutate( - AESTDT = ymd(AESTDTC) -) - -input_ex <- tibble::tribble( - ~STUDYID, ~USUBJID, ~EXSTDTC, ~EXENDTC, ~EXSEQ, ~EXDOSE, ~EXTRT, - "my_study", "subject1", "2020-01-01", "2020-01-01", 1, 10, "treatment", - "my_study", "subject1", "2020-08-29", "2020-08-29", 2, 10, "treatment", - "my_study", "subject1", "2020-09-02", "2020-09-02", 3, 10, "treatment", - "my_study", "subject1", "2020-10-20", "2020-10-20", 4, 10, "treatment", - "my_study", "subject2", "2019-05-25", "2019-05-25", 1, 0, "placebo", - "my_study", "subject2", "2020-01-20", "2020-01-20", 2, 0, "placebo", - "my_study", "subject3", "2020-03-15", "2020-03-15", 1, 10, "treatment" -) %>% - mutate(EXSTDT = as.Date(EXSTDTC), EXENDT = as.Date(EXENDTC)) - -# derive_var_last_dose_date ---- -## Test 1: works as expected output_datetime = FALSE ---- -test_that("derive_var_last_dose_date Test 1: works as expected output_datetime = FALSE", { - expected_output <- tibble::tribble( - ~STUDYID, ~USUBJID, ~AESEQ, ~AESTDTC, ~LDOSEDTM, - "my_study", "subject1", 1, "2020-01-02", "2020-01-01", - "my_study", "subject1", 2, "2020-08-31", "2020-08-29", - "my_study", "subject1", 3, "2020-10-10", "2020-09-02", - "my_study", "subject2", 1, "2019-05-15", NA_character_, - "my_study", "subject2", 2, "2020-02-20", "2020-01-20", - "my_study", "subject3", 1, "2020-03-02", NA_character_, - "my_study", "subject4", 1, "2020-11-02", NA_character_ - ) %>% - mutate( - LDOSEDTM = as.Date(LDOSEDTM), - AESTDT = ymd(AESTDTC) - ) - expect_error( - derive_var_last_dose_date( - input_ae, - input_ex, - filter_ex = (EXDOSE > 0) | (EXDOSE == 0 & EXTRT == "placebo"), - by_vars = exprs(STUDYID, USUBJID), - dose_date = EXENDT, - analysis_date = AESTDT, - new_var = LDOSEDTM, - single_dose_condition = (EXSTDTC == EXENDTC), - output_datetime = FALSE, - traceability_vars = NULL - ), - class = "lifecycle_error_deprecated" - ) -}) diff --git a/tests/testthat/test-derive_var_ontrtfl.R b/tests/testthat/test-derive_var_ontrtfl.R index 8167e41554..905790e084 100644 --- a/tests/testthat/test-derive_var_ontrtfl.R +++ b/tests/testthat/test-derive_var_ontrtfl.R @@ -449,7 +449,7 @@ test_that("derive_var_ontrtfl Test 16: expected deprecation messaging", { # noli ) # all flags should be "Y" because span_period flag is TRUE - lifecycle::expect_deprecated( + expect_error( derive_var_ontrtfl( adcm, start_date = ASTDT, @@ -457,11 +457,12 @@ test_that("derive_var_ontrtfl Test 16: expected deprecation messaging", { # noli ref_start_date = TRTSDT, ref_end_date = TRTEDT, span_period = "Y" - ) + ), + class = "lifecycle_error_deprecated" ) # first obs started before treatment, and it should NOT be flagged - lifecycle::expect_deprecated( + expect_error( derive_var_ontrtfl( adcm, start_date = ASTDT, @@ -469,6 +470,7 @@ test_that("derive_var_ontrtfl Test 16: expected deprecation messaging", { # noli ref_start_date = TRTSDT, ref_end_date = TRTEDT, span_period = NULL - ) + ), + class = "lifecycle_error_deprecated" ) }) diff --git a/tests/testthat/test-derive_var_shift.R b/tests/testthat/test-derive_var_shift.R index bebbabb1f4..343f51016c 100644 --- a/tests/testthat/test-derive_var_shift.R +++ b/tests/testthat/test-derive_var_shift.R @@ -142,7 +142,7 @@ test_that("derive_var_shift Test 5: Test deprecation warning of na_val argument" "P02", "SODIUM", 147, "Y", "HIGH", "HIGH" ) - expect_warning( + expect_error( derive_var_shift( input, new_var = SHIFT1, @@ -151,6 +151,6 @@ test_that("derive_var_shift Test 5: Test deprecation warning of na_val argument" na_val = "MISSING", sep_val = " - " ), - class = "lifecycle_warning_deprecated" + class = "lifecycle_error_deprecated" ) }) diff --git a/tests/testthat/test-derive_vars_last_dose.R b/tests/testthat/test-derive_vars_last_dose.R deleted file mode 100644 index 2a99d04734..0000000000 --- a/tests/testthat/test-derive_vars_last_dose.R +++ /dev/null @@ -1,52 +0,0 @@ -input_ae <- tibble::tribble( - ~STUDYID, ~USUBJID, ~AESEQ, ~AESTDTC, - "my_study", "subject1", 1, "2020-01-02", - "my_study", "subject1", 2, "2020-08-31", - "my_study", "subject1", 3, "2020-10-10", - "my_study", "subject2", 1, "2019-05-15", - "my_study", "subject2", 2, "2020-02-20", - "my_study", "subject3", 1, "2020-03-02", - "my_study", "subject4", 1, "2020-11-02" -) %>% - mutate( - AESTDT = ymd(AESTDTC) - ) - -input_ex <- tibble::tribble( - ~STUDYID, ~USUBJID, ~EXSTDTC, ~EXENDTC, ~EXSEQ, ~EXDOSE, ~EXTRT, - "my_study", "subject1", "2020-01-01", "2020-01-01", 1, 10, "treatment", - "my_study", "subject1", "2020-08-29", "2020-08-29", 2, 10, "treatment", - "my_study", "subject1", "2020-09-02", "2020-09-02", 3, 10, "treatment", - "my_study", "subject1", "2020-10-20", "2020-10-20", 4, 10, "treatment", - "my_study", "subject2", "2019-05-25", "2019-05-25", 1, 0, "placebo", - "my_study", "subject2", "2020-01-20", "2020-01-20", 2, 0, "placebo", - "my_study", "subject3", "2020-03-15", "2020-03-15", 1, 10, "treatment" -) %>% - mutate(EXSTDT = as.Date(EXSTDTC), EXENDT = as.Date(EXENDTC)) - -# derive_vars_last_dose ---- -## Test 1: function works as expected and returns an error message ---- -test_that("derive_vars_last_dose Test 1: function works as expected and returns an error message", { - expected_output <- mutate( - input_ae, - EXSTDT = as.Date(c("2020-01-01", "2020-08-29", "2020-09-02", NA, "2020-01-20", NA, NA)), - EXENDT = as.Date(c("2020-01-01", "2020-08-29", "2020-09-02", NA, "2020-01-20", NA, NA)), - EXSEQ = c(1, 2, 3, NA, 2, NA, NA), - EXDOSE = c(10, 10, 10, NA, 0, NA, NA), - EXTRT = c("treatment", "treatment", "treatment", NA, "placebo", NA, NA) - ) - expect_error( - derive_vars_last_dose( - input_ae, - input_ex, - filter_ex = (EXDOSE > 0) | (EXDOSE == 0 & EXTRT == "placebo"), - by_vars = exprs(STUDYID, USUBJID), - dose_date = EXENDT, - new_vars = exprs(EXDOSE, EXTRT, EXSEQ, EXENDT, EXSTDT), - analysis_date = AESTDT, - single_dose_condition = (EXSTDTC == EXENDTC), - traceability_vars = NULL - ), - class = "lifecycle_error_deprecated" - ) -}) diff --git a/tests/testthat/test-restrict_derivation.R b/tests/testthat/test-restrict_derivation.R index 5c8eca4258..ab908dd524 100644 --- a/tests/testthat/test-restrict_derivation.R +++ b/tests/testthat/test-restrict_derivation.R @@ -1,5 +1,5 @@ # restrict_derivation ---- -## restrict_derivation Test 1: restrict derivation with parameters ---- +## Test 1: restrict derivation with parameters ---- test_that("restrict_derivation Test 1: restrict derivation with parameters", { adlb <- tibble::tribble( ~USUBJID, ~AVISITN, ~AVAL, ~ABLFL, @@ -28,7 +28,7 @@ test_that("restrict_derivation Test 1: restrict derivation with parameters", { ) }) -## restrict_derivation Test 2: restrict derivation without parameters ---- +## Test 2: restrict derivation without parameters ---- test_that("restrict_derivation Test 2: restrict derivation without parameters", { adlb <- tibble::tribble( ~USUBJID, ~AVISITN, ~AVAL, ~ABLFL, ~BASE, @@ -55,7 +55,7 @@ test_that("restrict_derivation Test 2: restrict derivation without parameters", ) }) -## restrict_derivation Test 3: access functions from the parent environment ---- +## Test 3: access functions from the parent environment ---- test_that("restrict_derivation Test 3: access functions from the parent environment", { my_derivation <- function(dataset, new_var) { mutate( @@ -81,3 +81,33 @@ test_that("restrict_derivation Test 3: access functions from the parent environm ) }) }) + +## Test 4: allow dplyr functions ---- +test_that("restrict_derivation Test 4: allow dplyr functions", { + adlb <- tibble::tribble( + ~USUBJID, ~AVISITN, ~AVAL, + "1", -1, 113, + "1", 0, 113, + "1", 3, 117, + "2", 0, 95, + "3", 0, 111, + "3", 1, 101, + "3", 2, 123 + ) + + actual <- restrict_derivation( + adlb, + derivation = mutate, + args = params(AVAL = AVAL + 1), + filter = USUBJID == "1" + ) + + expected <- adlb %>% + mutate(AVAL = ifelse(USUBJID == "1", AVAL + 1, AVAL)) + + expect_dfs_equal( + base = expected, + compare = actual, + keys = c("USUBJID", "AVISITN") + ) +}) diff --git a/tests/testthat/test-roxygen2.R b/tests/testthat/test-roxygen2.R new file mode 100644 index 0000000000..a0b31eb094 --- /dev/null +++ b/tests/testthat/test-roxygen2.R @@ -0,0 +1,16 @@ +# roxygen_param_dataset ---- +## Test 1: Input dataset standardized text works ---- +test_that("roxygen_param_dataset Test 1: Input dataset standardized text works", { + expect_equal("Input dataset", roxygen_param_dataset(expected_vars = NULL)) +}) + +## Test 2: Input dataset standardized text works ---- +test_that("roxygen_param_dataset Test 2: Input dataset standardized text works", { + expect_equal( + paste0( + "Input dataset \n \n", + "The variables specified by the `by_vars` argument(s) to be expected." + ), + roxygen_param_dataset(expected_vars = c("by_vars")) + ) +}) diff --git a/vignettes/adsl.Rmd b/vignettes/adsl.Rmd index 00ff322785..0af1f414f0 100644 --- a/vignettes/adsl.Rmd +++ b/vignettes/adsl.Rmd @@ -751,7 +751,7 @@ The following functions are helpful for many ADSL derivations: - `derive_vars_merged()` - Merge Variables from a Dataset to the Input Dataset - `derive_var_merged_exist_flag()` - Merge an Existence Flag - - `derive_var_merged_summary()` - Merge a Summary Variable + - `derive_var_merged_summary()` - Merge Summary Variables See also [Generic Functions](generic.html). diff --git a/vignettes/bds_finding.Rmd b/vignettes/bds_finding.Rmd index ed8e715ece..20e2fbdf62 100644 --- a/vignettes/bds_finding.Rmd +++ b/vignettes/bds_finding.Rmd @@ -990,9 +990,10 @@ Set `DTYPE` to `AVERAGE`. advs_ex2 <- derive_summary_records( advs, by_vars = exprs(STUDYID, USUBJID, PARAMCD, VISITNUM, ADT), - analysis_var = AVAL, - summary_fun = mean, - set_values_to = exprs(DTYPE = "AVERAGE") + set_values_to = exprs( + AVAL = mean(AVAL), + DTYPE = "AVERAGE" + ) ) ``` diff --git a/vignettes/pk_adnca.Rmd b/vignettes/pk_adnca.Rmd index 38c60f4805..1cabe5c7de 100644 --- a/vignettes/pk_adnca.Rmd +++ b/vignettes/pk_adnca.Rmd @@ -914,10 +914,8 @@ Adding attributes to the `ADPC` file will be discussed # Programming Population PK (ADPPK) Analysis Data -The Population PK Analysis Data (ADPPK) follows the forthcoming CDISC -Implementation Guide -(). The -programming workflow for Population PK (ADPPK) Analysis Data is similar +The Population PK Analysis Data (ADPPK) follows the CDISC Implementation Guide +(). The programming workflow for Population PK (ADPPK) Analysis Data is similar to the NCA Programming flow with a few key differences. Population PK models generally make use of nonlinear mixed effects models that require numeric variables. The data used in the models will include both dosing diff --git a/vignettes/questionnaires.Rmd b/vignettes/questionnaires.Rmd index 57d4a6020b..12415d00ae 100644 --- a/vignettes/questionnaires.Rmd +++ b/vignettes/questionnaires.Rmd @@ -142,11 +142,10 @@ adgad7 <- adqs %>% filter(PARCAT1 == "GAD-7 V2") %>% derive_summary_records( by_vars = exprs(STUDYID, USUBJID, AVISIT, ADT, ADY, TRTSDT, DTHCAUS), - analysis_var = AVAL, - summary_fun = function(x) sum(x, na.rm = TRUE), # Select records contributing to total score filter = str_detect(PARAMCD, "GAD020[1-7]"), set_values_to = exprs( + AVAL = sum(AVAL, na.rm = TRUE), PARAMCD = "GAD02TS", PARAM = "GAD02-Total Score - Analysis" ) @@ -171,19 +170,16 @@ adgdssf <- adqs %>% filter(PARCAT1 == "GDS SHORT FORM") %>% derive_summary_records( by_vars = exprs(STUDYID, USUBJID, AVISIT, ADT, ADY, TRTSDT, DTHCAUS), - analysis_var = AVAL, - summary_fun = function(x) { - compute_scale( - x, + # Select records contributing to total score + filter = str_detect(PARAMCD, "GDS02[01][0-9]"), + set_values_to = exprs( + AVAL = compute_scale( + AVAL, source_range = c(0, 1), target_range = c(0, 15), min_n = 10 ) %>% - ceiling() - }, - # Select records contributing to total score - filter = str_detect(PARAMCD, "GDS02[01][0-9]"), - set_values_to = exprs( + ceiling(), PARAMCD = "GDS02TS", PARAM = "GDS02- Total Score - Analysis" ) @@ -523,9 +519,8 @@ adgdssf <- adgdssf %>% derive_summary_records( filter = str_detect(PARAMCD, "GDS02[01][0-9]"), by_vars = exprs(USUBJID, AVISIT), - analysis_var = AVAL, - summary_fun = function(x) sum(!is.na(x)) / 15 >= 0.9, set_values_to = exprs( + AVAL = sum(!is.na(AVAL)) / 15 >= 0.9, PARAMCD = "COMPL90P", PARAM = "Completed at least 90% of questions?", AVALC = if_else(AVAL == 1, "YES", "NO") @@ -564,7 +559,7 @@ parm_visit_ref <- crossing( adgdssf <- adgdssf %>% derive_expected_records( - dataset_expected_obs = parm_visit_ref, + dataset_ref = parm_visit_ref, by_vars = exprs(USUBJID), set_values_to = exprs( filled_in = 1 @@ -573,9 +568,8 @@ adgdssf <- adgdssf %>% derive_summary_records( filter = str_detect(PARAMCD, "GDS02[01][0-9]"), by_vars = exprs(USUBJID, AVISIT), - analysis_var = AVAL, - summary_fun = function(x) all(!is.na(x)), set_values_to = exprs( + AVAL = all(!is.na(AVAL)), PARAMCD = "COMPLALL", PARAM = "Completed all questions?", AVALC = if_else(AVAL == 1, "YES", "NO")