diff --git a/R/derive_blfl.R b/R/derive_blfl.R index 8cd5cf1..1f127e5 100644 --- a/R/derive_blfl.R +++ b/R/derive_blfl.R @@ -354,9 +354,9 @@ derive_blfl <- function(sdtm_in, # Filter out rows where --ORRES is missing. Filter out --ORRES in # ("ND", "NOT DONE") as well. - bad_orres_rows <- is.na(ds_mod[[domain_prefixed_names["orres"]]]) | - trimws(ds_mod[[domain_prefixed_names["orres"]]]) %in% c("ND", "NOT DONE", "") - ds_mod <- ds_mod[!bad_orres_rows, ] + ds_mod <- ds_mod |> + dplyr::filter(!(is.na(.data[[domain_prefixed_names["orres"]]]) | + trimws(.data[[domain_prefixed_names["orres"]]]) %in% c("ND", "NOT DONE", ""))) # Filter out rows where --STAT is not equal to "NOT DONE" ds_mod <- @@ -374,10 +374,10 @@ derive_blfl <- function(sdtm_in, } # Checking for columns of interest - con_col <- c(domain_prefixed_names[c("testcd", "dtc", "var_tpt")], "VISIT") + con_col <- c(domain_prefixed_names[c("testcd", "dtc", "tpt")], "VISIT") - # Drop those columns from the list which are not present in ds_in - con_col <- con_col[con_col %in% names(sdtm_in)] + # Drop those columns from the list which are not present in ds_mod + con_col <- con_col[con_col %in% names(ds_mod)] # Check for any column which is all NA and removing it from con_col list h <- which(sapply(ds_mod, function(x) all(is.na(x)))) @@ -438,16 +438,17 @@ derive_blfl <- function(sdtm_in, dplyr::filter( dom_dt == ref_dt, is.na(dom_tm) | is.na(ref_tm) | dom_tm == ref_tm, - (VISIT %in% baseline_visits & get(domain_prefixed_names["tpt"]) %in% baseline_timepoints) | + (VISIT %in% baseline_visits & !!rlang::sym(domain_prefixed_names["tpt"]) %in% baseline_timepoints) | (VISIT %in% baseline_visits & length(baseline_timepoints) == 0L) | - (get(domain_prefixed_names["tpt"]) %in% baseline_timepoints & length(baseline_visits) == 0L) + (!!rlang::sym(domain_prefixed_names["tpt"]) %in% baseline_timepoints & length(baseline_visits) == 0L) ) # Combine (*A) and (*B) and (*C) - ds_base <- rbind(ds_subset_lt, ds_subset_eq_1, ds_subset_eq_2) + ds_base <- dplyr::bind_rows(ds_subset_lt, ds_subset_eq_1, ds_subset_eq_2) # Sort the rows in ascending order with respect to columns from con_col - ds_base <- dplyr::arrange_at(ds_base, c("USUBJID", con_col)) + ds_base <- ds_base |> + dplyr::arrange(USUBJID, !!!rlang::syms(con_col)) if (nrow(ds_base) == 0L) { cli::cli_inform("There are no baseline records.")