diff --git a/R/derive_params_growth_age.R b/R/derive_params_growth_age.R index 7abceac..5a61ea1 100644 --- a/R/derive_params_growth_age.R +++ b/R/derive_params_growth_age.R @@ -8,12 +8,6 @@ #' The variables specified in `sex`, `age`, `age_unit`, `parameter`, `analysis_var` #' are expected to be in the dataset. #' -#' @param by_vars Grouping variables -#' -#' The variables from `dataset` which identifies a unique subject and their visit is expected. -#' -#' *Permitted Values*: A list of variables created by `exprs()`, e.g `exprs(USUBJID, VISIT)`. -#' #' @param sex Sex #' #' A character vector is expected. @@ -183,7 +177,6 @@ #' #' derive_params_growth_age( #' advs, -#' by_vars = exprs(STUDYID, USUBJID, VISIT), #' sex = SEX, #' age = AGECUR, #' age_unit = AGECURU, @@ -201,7 +194,6 @@ #' ) #' ) derive_params_growth_age <- function(dataset, - by_vars = NULL, sex, age, age_unit, @@ -213,17 +205,13 @@ derive_params_growth_age <- function(dataset, set_values_to_sds = NULL, set_values_to_pctl = NULL) { # Apply assertions to each argument to ensure each object is appropriate class - if (is.null(by_vars)) { - warning("A list of variables created by `exprs()` is expected in argument `by_vars`.") - } - assert_vars(by_vars) sex <- assert_symbol(enexpr(sex)) age <- assert_symbol(enexpr(age)) age_unit <- assert_symbol(enexpr(age_unit)) analysis_var <- assert_symbol(enexpr(analysis_var)) assert_data_frame( dataset, - required_vars = expr_c(sex, age, age_unit, analysis_var, by_vars) + required_vars = expr_c(sex, age, age_unit, analysis_var) ) assert_data_frame(meta_criteria, required_vars = exprs(SEX, AGE, AGEU, L, M, S)) @@ -279,11 +267,6 @@ derive_params_growth_age <- function(dataset, ) %>% filter(!is.na(metadata_age)) - by_exprs <- enexpr(by_vars) - by_antijoin <- setNames(as.character(by_exprs), as.character(by_exprs)) - # unmatched_records <- anti_join(dataset2, added_records, by = by_antijoin) %>% - # filter(!!enexpr(parameter)) - dataset_final <- dataset # create separate records objects as appropriate depending if user specific sds and/or pctl @@ -322,10 +305,7 @@ derive_params_growth_age <- function(dataset, select(-c(P95, Sigma)) } - # unmatched_sds <- unmatched_records %>% - # mutate(!!!set_values_to_sds) - - dataset_final <- bind_rows(dataset, add_sds) %>% # , unmatched_sds) %>% + dataset_final <- bind_rows(dataset, add_sds) %>% select(-c(L, M, S, sex_join, ageu_join, metadata_age, temp_val, temp_z)) } @@ -364,13 +344,10 @@ derive_params_growth_age <- function(dataset, select(-c(P95, Sigma)) } else { add_pctl <- add_pctl %>% - mutate(AVAL = pnorm(AVAL) * 100) + mutate(AVAL = pnorm(temp_z) * 100) } - # unmatched_pctl <- unmatched_records %>% - # mutate(!!!set_values_to_pctl) - - dataset_final <- bind_rows(dataset_final, add_pctl) %>% # , unmatched_pctl) %>% + dataset_final <- bind_rows(dataset_final, add_pctl) %>% select(-c(L, M, S, sex_join, ageu_join, metadata_age, temp_val, temp_z)) } diff --git a/R/derive_params_growth_height.R b/R/derive_params_growth_height.R index e32ebde..5b1414c 100644 --- a/R/derive_params_growth_height.R +++ b/R/derive_params_growth_height.R @@ -9,12 +9,6 @@ #' The variables specified in `sex`, `height`, `height_unit`, `parameter`, `analysis_var` #' are expected to be in the dataset. #' -#' @param by_vars Grouping variables -#' -#' The variables from `dataset` which identifies a unique subject and their visit is expected. -#' -#' *Permitted Values*: A list of variables created by `exprs()`, e.g `exprs(USUBJID, VISIT)`. -#' #' @param sex Sex #' #' A character vector is expected. @@ -173,7 +167,6 @@ #' #' derive_params_growth_height( #' advs_under2, -#' by_vars = exprs(STUDYID, USUBJID, VISIT), #' sex = SEX, #' height = HGTTMP, #' height_unit = HGTTMPU, @@ -191,7 +184,6 @@ #' ) #' ) derive_params_growth_height <- function(dataset, - by_vars = NULL, sex, height, height_unit, @@ -202,17 +194,13 @@ derive_params_growth_height <- function(dataset, set_values_to_sds = NULL, set_values_to_pctl = NULL) { # Apply assertions to each argument to ensure each object is appropriate class - if (is.null(by_vars)) { - warning("A list of variables created by `exprs()` is expected in argument `by_vars`.") - } - assert_vars(by_vars) sex <- assert_symbol(enexpr(sex)) height <- assert_symbol(enexpr(height)) height_unit <- assert_symbol(enexpr(height_unit)) analysis_var <- assert_symbol(enexpr(analysis_var)) assert_data_frame( dataset, - required_vars = expr_c(sex, height, height_unit, analysis_var, by_vars) + required_vars = expr_c(sex, height, height_unit, analysis_var) ) assert_data_frame( meta_criteria, @@ -266,11 +254,6 @@ derive_params_growth_height <- function(dataset, ) %>% filter(!is.na(meta_height)) - by_exprs <- enexpr(by_vars) - by_antijoin <- setNames(as.character(by_exprs), as.character(by_exprs)) - # unmatched_records <- anti_join(dataset2, added_records, by = by_antijoin) %>% - # filter(!!enexpr(parameter)) - dataset_final <- dataset # create separate records objects as appropriate depending if user specific sds and/or pctl @@ -293,10 +276,8 @@ derive_params_growth_height <- function(dataset, ) ) } - # unmatched_sds <- unmatched_records %>% - # mutate(!!!set_values_to_sds) - dataset_final <- bind_rows(dataset, add_sds) %>% # , unmatched_sds) %>% + dataset_final <- bind_rows(dataset, add_sds) %>% select(-c(L, M, S, sex_join, heightu_join, meta_height, temp_val, temp_z)) } @@ -321,12 +302,9 @@ derive_params_growth_height <- function(dataset, } add_pctl <- add_pctl %>% - mutate(AVAL = pnorm(AVAL) * 100) - - # unmatched_pctl <- unmatched_records %>% - # mutate(!!!set_values_to_pctl) + mutate(AVAL = pnorm(temp_z) * 100) - dataset_final <- bind_rows(dataset_final, add_pctl) %>% # , unmatched_pctl) %>% + dataset_final <- bind_rows(dataset_final, add_pctl) %>% select(-c(L, M, S, sex_join, heightu_join, meta_height, temp_val, temp_z)) } diff --git a/inst/templates/ad_advs.R b/inst/templates/ad_advs.R index 1544f12..154b6be 100644 --- a/inst/templates/ad_advs.R +++ b/inst/templates/ad_advs.R @@ -295,7 +295,6 @@ advs_age_wt <- advs %>% slice_derivation( derivation = derive_params_growth_age, args = params( - by_vars = c(get_admiral_option("subject_keys"), exprs(AVISIT)), sex = SEX, age = AAGECUR, age_unit = AAGECURU, @@ -329,7 +328,6 @@ advs_age_wt <- advs %>% slice_derivation( derivation = derive_params_growth_age, args = params( - by_vars = c(get_admiral_option("subject_keys"), exprs(AVISIT)), sex = SEX, age = AAGECUR, age_unit = AAGECURU, @@ -364,7 +362,6 @@ advs_age_wt <- advs %>% advs_age <- advs_age_wt %>% derive_params_growth_age( - by_vars = c(get_admiral_option("subject_keys"), exprs(AVISIT)), sex = SEX, age = AAGECUR, age_unit = AAGECURU, @@ -381,7 +378,6 @@ advs_age <- advs_age_wt %>% ) ) %>% derive_params_growth_age( - by_vars = c(get_admiral_option("subject_keys"), exprs(AVISIT)), sex = SEX, age = AAGECUR, age_unit = AAGECURU, @@ -408,7 +404,6 @@ advs_ht_lgth <- advs %>% restrict_derivation( derivation = derive_params_growth_height, args = params( - by_vars = c(get_admiral_option("subject_keys"), exprs(AVISIT)), sex = SEX, height = HGTTMP, height_unit = HGTTMPU, diff --git a/man/derive_params_growth_age.Rd b/man/derive_params_growth_age.Rd index dd9916a..690e0fd 100644 --- a/man/derive_params_growth_age.Rd +++ b/man/derive_params_growth_age.Rd @@ -6,7 +6,6 @@ \usage{ derive_params_growth_age( dataset, - by_vars = NULL, sex, age, age_unit, @@ -25,12 +24,6 @@ derive_params_growth_age( The variables specified in \code{sex}, \code{age}, \code{age_unit}, \code{parameter}, \code{analysis_var} are expected to be in the dataset.} -\item{by_vars}{Grouping variables - -The variables from \code{dataset} which identifies a unique subject and their visit is expected. - -\emph{Permitted Values}: A list of variables created by \code{exprs()}, e.g \code{exprs(USUBJID, VISIT)}.} - \item{sex}{Sex A character vector is expected. diff --git a/man/derive_params_growth_height.Rd b/man/derive_params_growth_height.Rd index 23849f2..13f0b53 100644 --- a/man/derive_params_growth_height.Rd +++ b/man/derive_params_growth_height.Rd @@ -7,7 +7,6 @@ based on Standard Growth Charts} \usage{ derive_params_growth_height( dataset, - by_vars = NULL, sex, height, height_unit, @@ -25,12 +24,6 @@ derive_params_growth_height( The variables specified in \code{sex}, \code{height}, \code{height_unit}, \code{parameter}, \code{analysis_var} are expected to be in the dataset.} -\item{by_vars}{Grouping variables - -The variables from \code{dataset} which identifies a unique subject and their visit is expected. - -\emph{Permitted Values}: A list of variables created by \code{exprs()}, e.g \code{exprs(USUBJID, VISIT)}.} - \item{sex}{Sex A character vector is expected. diff --git a/tests/testthat/test-derive_params_growth_age.R b/tests/testthat/test-derive_params_growth_age.R index 70cbb9c..161c846 100644 --- a/tests/testthat/test-derive_params_growth_age.R +++ b/tests/testthat/test-derive_params_growth_age.R @@ -20,7 +20,6 @@ test_that("derive_params_growth_age Test 1: Weight SDS and percentile works", { ) actual <- derive_params_growth_age( dataset = vs_data, - by_vars = exprs(STUDYID, USUBJID, VISIT), sex = SEX, age = AGECUR, age_unit = AGEU, @@ -80,7 +79,6 @@ test_that("derive_params_growth_age Test 2: Height SDS and percentile works (P50 actual <- derive_params_growth_age( dataset = vs_data, - by_vars = exprs(STUDYID, USUBJID, VISIT), sex = SEX, age = AGECUR, age_unit = AGEU, @@ -139,7 +137,6 @@ test_that("derive_params_growth_age Test 3: BMI SDS and percentile works (Z-scor actual <- derive_params_growth_age( dataset = vs_data, - by_vars = exprs(STUDYID, USUBJID, VISIT), sex = SEX, age = AGECUR, age_unit = AGEU, @@ -196,7 +193,6 @@ test_that("derive_params_growth_age Test 4: Head circumference SDS and percentil actual <- derive_params_growth_age( dataset = vs_data, - by_vars = exprs(STUDYID, USUBJID, VISIT), sex = SEX, age = AGECUR, age_unit = AGEU, @@ -249,7 +245,6 @@ test_that("derive_params_growth_age Test 5: Extreme BMI value derivation works", actual <- derive_params_growth_age( dataset = vs_data, - by_vars = exprs(STUDYID, USUBJID, VISIT), sex = SEX, age = AGECUR, age_unit = AGEU, @@ -319,7 +314,6 @@ test_that("derive_params_growth_age Test 6: Test out of bound ages", { actual <- derive_params_growth_age( dataset = vs_data, - by_vars = exprs(STUDYID, USUBJID, VISIT), sex = SEX, age = AGECUR, age_unit = AGEU, @@ -357,7 +351,6 @@ test_that("derive_params_growth_age Test 7: Test missing anthropocentric values" actual <- derive_params_growth_age( dataset = vs_data, - by_vars = exprs(STUDYID, USUBJID, VISIT), sex = SEX, age = AGECUR, age_unit = AGEU, @@ -396,7 +389,6 @@ test_that("derive_params_growth_age Test 8: Age unit/Metadata in months works", ) actual <- derive_params_growth_age( dataset = vs_data, - by_vars = exprs(STUDYID, USUBJID, VISIT), sex = SEX, age = AGECUR, age_unit = AGEU, @@ -446,7 +438,6 @@ test_that("derive_params_growth_age Test 8: WHO outlier adjustment works", { actual <- derive_params_growth_age( vs_data, - by_vars = exprs(STUDYID, USUBJID, VISIT), sex = SEX, age = AGECUR, age_unit = AGEU, diff --git a/tests/testthat/test-derive_params_growth_height.R b/tests/testthat/test-derive_params_growth_height.R index 2428325..8acffa3 100644 --- a/tests/testthat/test-derive_params_growth_height.R +++ b/tests/testthat/test-derive_params_growth_height.R @@ -21,7 +21,6 @@ test_that("derive_params_growth_height Test 1: derive_params_growth_height works actual <- derive_params_growth_height( dataset = vs_data, - by_vars = exprs(STUDYID, USUBJID, VISIT), sex = SEX, height = HEIGHT, height_unit = HEIGHTU, @@ -71,7 +70,6 @@ test_that("derive_params_growth_height Test 2: derives correct z-scores/percenti out <- derive_params_growth_height( dataset = vs_data, - by_vars = exprs(USUBJID, VISIT), sex = SEX, height = HEIGHT, height_unit = HEIGHTU, @@ -108,7 +106,6 @@ test_that("derive_params_growth_height Test 3: handles missing height/lengths", out <- derive_params_growth_height( dataset = vs_data, - by_vars = exprs(USUBJID, VISIT), sex = SEX, height = HEIGHT, height_unit = HEIGHTU, @@ -149,7 +146,6 @@ test_that("derive_params_growth_height Test 4: returns expected error message", expect_error( derive_params_growth_height( dataset = vs_data, - by_vars = exprs(USUBJID, VISIT), sex = SEX, height = HEIGHT, height_unit = HEIGHTU, @@ -176,7 +172,6 @@ test_that("derive_params_growth_height Test 6: WHO outlier adjustment works", { actual <- derive_params_growth_height( dataset = vs_data, - by_vars = exprs(USUBJID, VISIT), sex = SEX, height = HEIGHT, height_unit = HEIGHTU, @@ -206,6 +201,7 @@ test_that("derive_params_growth_height Test 6: WHO outlier adjustment works", { expect_equal( filter(actual, PARAMCD %in% c("WGHSDS", "WGHPCTL")) %>% pull(AVAL), - c(expected_sds, expected_pctl) + c(expected_sds, expected_pctl), + tolerance = 0.001 ) }) diff --git a/vignettes/advs.Rmd b/vignettes/advs.Rmd index 414a665..040dfb5 100644 --- a/vignettes/advs.Rmd +++ b/vignettes/advs.Rmd @@ -393,7 +393,6 @@ advs <- advs %>% slice_derivation( derivation = derive_params_growth_age, args = params( - by_vars = c(get_admiral_option("subject_keys"), exprs(AVISIT)), sex = SEX, age = AAGECUR, age_unit = AAGECURU, @@ -481,7 +480,6 @@ advs <- advs %>% restrict_derivation( derivation = derive_params_growth_height, args = params( - by_vars = c(get_admiral_option("subject_keys"), exprs(AVISIT)), sex = SEX, height = HGTTMP, height_unit = HGTTMPU,