Skip to content

Commit

Permalink
remove byvars reference
Browse files Browse the repository at this point in the history
  • Loading branch information
zdz2101 committed Aug 5, 2024
1 parent a1091f2 commit 966a393
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 89 deletions.
31 changes: 4 additions & 27 deletions R/derive_params_growth_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -183,7 +177,6 @@
#'
#' derive_params_growth_age(
#' advs,
#' by_vars = exprs(STUDYID, USUBJID, VISIT),
#' sex = SEX,
#' age = AGECUR,
#' age_unit = AGECURU,
Expand All @@ -201,7 +194,6 @@
#' )
#' )
derive_params_growth_age <- function(dataset,
by_vars = NULL,
sex,
age,
age_unit,
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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))
}

Expand Down
30 changes: 4 additions & 26 deletions R/derive_params_growth_height.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -173,7 +167,6 @@
#'
#' derive_params_growth_height(
#' advs_under2,
#' by_vars = exprs(STUDYID, USUBJID, VISIT),
#' sex = SEX,
#' height = HGTTMP,
#' height_unit = HGTTMPU,
Expand All @@ -191,7 +184,6 @@
#' )
#' )
derive_params_growth_height <- function(dataset,
by_vars = NULL,
sex,
height,
height_unit,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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))
}

Expand All @@ -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))
}

Expand Down
5 changes: 0 additions & 5 deletions inst/templates/ad_advs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions man/derive_params_growth_age.Rd

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

7 changes: 0 additions & 7 deletions man/derive_params_growth_height.Rd

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

9 changes: 0 additions & 9 deletions tests/testthat/test-derive_params_growth_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions tests/testthat/test-derive_params_growth_height.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
)
})
2 changes: 0 additions & 2 deletions vignettes/advs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 966a393

Please sign in to comment.