Skip to content

Commit

Permalink
#2468 derive_vars_crit_flag: add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bundfussr committed Jun 25, 2024
1 parent 65f7e33 commit 09de412
Show file tree
Hide file tree
Showing 24 changed files with 162 additions and 54 deletions.
73 changes: 64 additions & 9 deletions R/derive_vars_crit_flag.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,92 @@
#' Derive Criterion Flag Variables `CRITy`, `CRITyFL`, and `CRITyFLN`
#'
#' Derives criterion flags based on the provided dataset, condition, and
#' description.
#' @description
#'
#' The function derives ADaM compliant criterion flags. I.e., if a criterion
#' flag can't be derived with this function, the derivation is not ADaM
#' compliant. It helps to ensure that
#' - the condition of the criterion depends only on variables of the same row,
#' - the `CRITyFL` is populated with valid values, i.e, either `"Y"` and `NA` or
#' `"Y"`, `"N"`, and `NA`.
#' - the `CRITy` variable is populated correctly, i.e.,
#' - set to a constant value within a parameter if `CRITyFL` is populated with
#' `"Y"`, `"N"`, and `NA` and
#' - set to a constant value within a parameter if the criterion condition is
#' fulfilled and to `NA` otherwise if `CRITyFL` is populated with `"Y"`, and
#' `NA`
#'
#' @param dataset Input dataset
#' @param crit_nr The criterion number
#' @param condition The condition for deriving the criterion flag.
#' @param crit_nr The criterion number, i.e., the `y` in `CRITy`
#'
#' *Permitted Values*: a positive integer
#' @param condition Condition for flagging records
#'
#' See description of the `values_yn` argument for details on how the
#' `CRITyFL` variable is populated.
#'
#' *Permitted Values*: an unquoted expression which evaluates to a logical (in
#' `dataset`)
#' @param description The description of the criterion
#'
#' The `CRITy` variable is set to the specified value.
#'
#' An expression can be specified to set the value depending on the parameter.
#' Please note that the value must be constant within a parameter.
#'
#' *Permitted Values*: an unquoted expression which evaluates to a character
#' (in `dataset`)
#' @param values_yn Should `"Y"` and `"N"` be used for `CRITyFL`?
#'
#' If set to `TRUE`, the `CRITyFL` variable is set to `"Y"` if the condition
#' (`condition`) evaluates to `TRUE`, it is set to `"N"` if the condition
#' evaluate to `FALSE`, and to `NA` if it evaluates to `NA`.
#'
#' Otherwise, the `CRITyFL` variable is set to `"Y"` if the condition
#' (`condition`) evaluates to `TRUE`, and to `NA` otherwise.
#'
#' *Permitted Values*: `TRUE`, `FALSE`
#' @param create_numeric_flag Create a numeric flag?
#'
#' If set to `TRUE`, the `CRITyFLN` variable is created. It is set to `1` if
#' `CRITyFL == "Y"`, it set to `0` if `CRITyFL == "N"`, and to `NA` otherwise.
#'
#' *Permitted Values*: `TRUE`, `FALSE`
#' @return The modified dataset with the derived criterion flag variable.
#' @return The input dataset with the variables `CRITy`, `CRITyFL`, and
#' optionally `CRITyFLN` added.
#'
#' @family der_gen
#' @keywords der_gen
#' @family der_bds_findings
#' @keywords der_bds_findings
#'
#' @export
#'
#' @examples
#' dataset <- data.frame(x = c(1, 2, 3), y = c(4, 5, 6))
#' derive_vars_crit_flag(dataset, crit_nr = 1, condition = x > 2, description = "Flag 1")
#' library(tibble)
#' adbds <- tribble(
#' ~PARAMCD, ~AVAL,
#' "AST", 42,
#' "AST", 52,
#' "AST", NA_real_,
#' "ALT", 33,
#' "ALT", 51
#' )
#'
#' # Create a criterion flag with values "Y" and NA
#' derive_vars_crit_flag(
#' adbds,
#' condition = AVAL > 50,
#' description = "Absolute value > 50"
#' )
#'
#' # Create criterion flag with values "Y", "N", and NA and parameter dependent
#' # criterion description
#' derive_vars_crit_flag(
#' adbds,
#' crit_nr = 2,
#' condition = AVAL > 50,
#' description = paste(PARAMCD, "> 50"),
#' values_yn = TRUE,
#' create_numeric_flag = TRUE
#' )
derive_vars_crit_flag <- function(dataset,
crit_nr = 1,
condition ,
Expand Down
3 changes: 2 additions & 1 deletion man/derive_basetype_records.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/derive_var_analysis_ratio.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/derive_var_anrind.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/derive_var_atoxgr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/derive_var_atoxgr_dir.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/derive_var_base.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/derive_var_chg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/derive_var_extreme_flag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/derive_var_joined_exist_flag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/derive_var_merged_ef_msrc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/derive_var_merged_exist_flag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/derive_var_merged_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/derive_var_obs_number.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/derive_var_ontrtfl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/derive_var_pchg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/derive_var_relative_flag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/derive_var_shift.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/derive_vars_computed.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 78 additions & 23 deletions man/derive_vars_crit_flag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 09de412

Please sign in to comment.