Skip to content

Commit

Permalink
Merge pull request #198 from pharmaverse/197_exprs@1627_exprs@208_exp…
Browse files Browse the repository at this point in the history
…rs@devel

Closes #197 197_exprs: replace vars() with exprs()
  • Loading branch information
bundfussr committed Feb 16, 2023
2 parents 6267d1d + a5b88bd commit 7cb09ee
Show file tree
Hide file tree
Showing 34 changed files with 324 additions and 317 deletions.
8 changes: 3 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ importFrom(admiraldev,assert_vars)
importFrom(admiraldev,assert_varval_list)
importFrom(admiraldev,enumerate)
importFrom(admiraldev,expect_dfs_equal)
importFrom(admiraldev,expr_c)
importFrom(admiraldev,extract_vars)
importFrom(admiraldev,filter_if)
importFrom(admiraldev,quo_c)
importFrom(admiraldev,squote)
importFrom(admiraldev,suppress_warning)
importFrom(admiraldev,vars2chr)
Expand All @@ -69,16 +69,14 @@ importFrom(dplyr,right_join)
importFrom(dplyr,select)
importFrom(dplyr,slice)
importFrom(dplyr,ungroup)
importFrom(dplyr,vars)
importFrom(lifecycle,deprecate_stop)
importFrom(lifecycle,deprecate_warn)
importFrom(lifecycle,deprecated)
importFrom(lubridate,days)
importFrom(magrittr,`%>%`)
importFrom(rlang,abort)
importFrom(rlang,enquo)
importFrom(rlang,enexpr)
importFrom(rlang,exprs)
importFrom(rlang,inform)
importFrom(rlang,quo_get_expr)
importFrom(rlang,quo_is_null)
importFrom(rlang,warn)
importFrom(tidyselect,all_of)
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# admiralonco 0.3.0

## Breaking Changes

- All function arguments which expected a list of quosures created by `vars()`
are now expecting a list of expressions created by `exprs()`. For example,
instead of `by_vars = vars(STUDYID, USUBJID)` `by_vars = exprs(STUDYID,
USUBJID)` must be used now.

# admiralonco 0.2.0

## Updates of Existing Functions
Expand Down
6 changes: 3 additions & 3 deletions R/admiralonco-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#' assert_integer_scalar assert_list_of assert_logical_scalar
#' assert_order_vars assert_param_does_not_exist assert_s3_class assert_symbol
#' assert_vars assert_varval_list enumerate expect_dfs_equal extract_vars
#' filter_if quo_c squote suppress_warning vars2chr
#' filter_if expr_c squote suppress_warning vars2chr
#' @importFrom dplyr arrange bind_rows case_when filter group_by if_else
#' left_join mutate rename right_join select slice vars ungroup
#' left_join mutate rename right_join select slice ungroup
#' @importFrom lifecycle deprecate_warn deprecated deprecate_stop
#' @importFrom lubridate days
#' @importFrom magrittr `%>%`
#' @importFrom rlang abort enquo inform quo_get_expr quo_is_null warn
#' @importFrom rlang abort enexpr exprs inform warn
#' @importFrom tidyselect all_of
"_PACKAGE"
14 changes: 8 additions & 6 deletions R/check_crpr.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#'
#' @param dataset A data frame
#'
#' @param order A list of variables created using `vars()` determining the order
#' @param order A list of variables created using `exprs()` determining the order
#' or the records
#'
#' @param msg The condition message
#'
#' @param subject_keys Variables to uniquely identify a subject
#'
#' A list of symbols created using `vars()` is expected.
#' A list of symbols created using `exprs()` is expected.
#'
#' @param check_type Type of message to issue when detecting PR after CR.
#'
Expand All @@ -32,6 +32,7 @@
#' library(dplyr)
#' library(lubridate)
#' library(admiralonco)
#' library(rlang)
#'
#' adrs <- tribble(
#' ~USUBJID, ~ADTC, ~AVALC,
Expand All @@ -48,7 +49,7 @@
#' STUDYID = "XX1234"
#' )
#'
#' signal_crpr(adrs, order = vars(ADT))
#' signal_crpr(adrs, order = exprs(ADT))
signal_crpr <- function(dataset,
order,
msg = "Dataset contains CR records followed by PR.",
Expand All @@ -62,7 +63,7 @@ signal_crpr <- function(dataset,
dataset,
by_vars = subject_keys,
order = order,
join_vars = vars(AVALC),
join_vars = exprs(AVALC),
join_type = "after",
filter = AVALC == "CR" & AVALC.join == "PR"
)
Expand All @@ -72,7 +73,7 @@ signal_crpr <- function(dataset,
dataset,
by_vars = subject_keys,
order = order,
join_vars = vars(AVALC),
join_vars = exprs(AVALC),
join_type = "before",
filter = AVALC == "PR" & AVALC.join == "CR"
)
Expand Down Expand Up @@ -120,6 +121,7 @@ signal_crpr <- function(dataset,
#' library(dplyr)
#' library(lubridate)
#' library(admiralonco)
#' library(rlang)
#'
#' adrs <- tribble(
#' ~USUBJID, ~ADTC, ~AVALC,
Expand All @@ -136,7 +138,7 @@ signal_crpr <- function(dataset,
#' STUDYID = "XX1234"
#' )
#'
#' signal_crpr(adrs, order = vars(ADT))
#' signal_crpr(adrs, order = exprs(ADT))
#'
#' get_crpr_dataset()
get_crpr_dataset <- function() {
Expand Down
32 changes: 15 additions & 17 deletions R/derive_param_bor.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,14 @@
#'
#' @param set_values_to New columns to set
#'
#' A named list returned by `vars()` defining the columns to be set for the
#' new parameter, e.g. `vars(PARAMCD = "BOR", PARAM = "Best Overall
#' A named list returned by `exprs()` defining the columns to be set for the
#' new parameter, e.g. `exprs(PARAMCD = "BOR", PARAM = "Best Overall
#' Response")` is expected. The values must be symbols, character strings,
#' numeric values, or `NA`.
#'
#' @param subject_keys Columns to uniquely identify a subject
#'
#' A list of symbols created using `vars()`.
#'
#' *Permitted Values:* an `vars` object
#' *Permitted Values:* A list of symbols created using `exprs()`.
#'
#' @examples
#'
Expand Down Expand Up @@ -209,8 +207,8 @@
#' select(-ADTC) %>%
#' derive_vars_merged(
#' dataset_add = adsl,
#' by_vars = vars(STUDYID, USUBJID),
#' new_vars = vars(TRTSDT)
#' by_vars = exprs(STUDYID, USUBJID),
#' new_vars = exprs(TRTSDT)
#' )
#'
#' pd_date <- date_source(
Expand Down Expand Up @@ -242,7 +240,7 @@
#' aval_fun = aval_fun_pass,
#' reference_date = TRTSDT,
#' ref_start_window = 28,
#' set_values_to = vars(
#' set_values_to = exprs(
#' PARAMCD = "BOR",
#' PARAM = "Best Overall Response"
#' )
Expand Down Expand Up @@ -274,25 +272,25 @@ derive_param_bor <- function(dataset,
# Assert statements (checked in order of signature) ----
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

reference_date <- assert_symbol(arg = enquo(reference_date))
reference_date <- assert_symbol(arg = enexpr(reference_date))

assert_vars(arg = subject_keys)

assert_data_frame(
arg = dataset,
required_vars = quo_c(
required_vars = expr_c(
subject_keys,
reference_date,
vars(PARAMCD, ADT, AVALC)
exprs(PARAMCD, ADT, AVALC)
)
)

assert_data_frame(
arg = dataset_adsl,
required_vars = quo_c(subject_keys)
required_vars = expr_c(subject_keys)
)

filter_source <- assert_filter_cond(arg = enquo(filter_source))
filter_source <- assert_filter_cond(arg = enexpr(filter_source))

assert_integer_scalar(
arg = ref_start_window,
Expand All @@ -308,7 +306,7 @@ derive_param_bor <- function(dataset,

assert_param_does_not_exist(
dataset = dataset,
param = quo_get_expr(set_values_to$PARAMCD)
param = set_values_to$PARAMCD
)

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down Expand Up @@ -341,7 +339,7 @@ derive_param_bor <- function(dataset,
err_msg <- sprintf(
"dataframe passed into %s argument with the filter %s has 0 records",
"dataset",
deparse(quo_get_expr(filter_source))
deparse(filter_source)
)

abort(err_msg)
Expand Down Expand Up @@ -410,7 +408,7 @@ derive_param_bor <- function(dataset,
) %>%
filter_extreme(
by_vars = subject_keys,
order = vars(tmp_order, ADT),
order = exprs(tmp_order, ADT),
mode = "first"
) %>%
select(-tmp_order)
Expand All @@ -433,7 +431,7 @@ derive_param_bor <- function(dataset,
" ",
names(set_values_to),
"=",
lapply(set_values_to, quo_get_expr),
set_values_to,
collapse = "\n"
),
"\n)\nError message:\n ",
Expand Down
30 changes: 15 additions & 15 deletions R/derive_param_clinbenefit.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@
#' @param clinben_vals A vector of response values to be considered when determining
#' clinical benefit.
#'
#' @param set_values_to A named list returned by `vars()` containing new variables
#' @param set_values_to A named list returned by `exprs()` containing new variables
#' and their static value to be populated for the clinical benefit rate parameter
#' records, e.g. `vars(PARAMCD = "CBR", PARAM = "Clinical Benefit Rate")`.
#' records, e.g. `exprs(PARAMCD = "CBR", PARAM = "Clinical Benefit Rate")`.
#'
#' @param subject_keys A named list returned by `vars()` containing variables
#' @param subject_keys A named list returned by `exprs()` containing variables
#' used to uniquely identify subjects.
#'
#' @return The input dataset with a new parameter for clinical benefit
Expand Down Expand Up @@ -157,8 +157,8 @@
#' mutate(STUDYID = "AB42", ANL01FL = "Y") %>%
#' derive_vars_merged(
#' dataset_add = adsl,
#' by_vars = vars(STUDYID, USUBJID),
#' new_vars = vars(TRTSDT)
#' by_vars = exprs(STUDYID, USUBJID),
#' new_vars = exprs(TRTSDT)
#' )
#'
#' pd <- date_source(
Expand All @@ -182,7 +182,7 @@
#' source_datasets = list(adrs = adrs),
#' reference_date = TRTSDT,
#' ref_start_window = 28,
#' set_values_to = vars(
#' set_values_to = exprs(
#' PARAMCD = "CBR"
#' )
#' ) %>%
Expand All @@ -200,26 +200,26 @@ derive_param_clinbenefit <- function(dataset,
set_values_to,
subject_keys = get_admiral_option("subject_keys")) {
# Assertions and quotes
reference_date <- assert_symbol(enquo(reference_date))
reference_date <- assert_symbol(enexpr(reference_date))
assert_vars(subject_keys)
assert_data_frame(
dataset_adsl,
required_vars = subject_keys
)
assert_data_frame(
dataset,
required_vars = quo_c(subject_keys, reference_date, vars(PARAMCD, AVALC, ADT))
required_vars = expr_c(subject_keys, reference_date, exprs(PARAMCD, AVALC, ADT))
)

filter_source <- assert_filter_cond(
enquo(filter_source),
enexpr(filter_source),
optional = FALSE
)

assert_function(aval_fun)
assert_s3_class(source_resp, "date_source", optional = FALSE)
assert_s3_class(source_pd, "date_source")
assert_list_of(source_datasets, "data.frame", optional = FALSE)
assert_s3_class(source_resp, "date_source")
assert_s3_class(source_pd, "date_source", optional = TRUE)
assert_list_of(source_datasets, "data.frame")
assert_character_vector(clinben_vals)

source_names <- names(source_datasets)
Expand Down Expand Up @@ -250,7 +250,7 @@ derive_param_clinbenefit <- function(dataset,

ref_start_window <- assert_integer_scalar(ref_start_window, subset = "non-negative")
assert_varval_list(set_values_to, optional = TRUE)
assert_param_does_not_exist(dataset, quo_get_expr(set_values_to$PARAMCD))
assert_param_does_not_exist(dataset, set_values_to$PARAMCD)

# ADSL variables
adsl_vars <- intersect(colnames(dataset_adsl), colnames(dataset))
Expand Down Expand Up @@ -295,7 +295,7 @@ derive_param_clinbenefit <- function(dataset,
ADT >= !!reference_date + days(ref_start_window)
) %>%
filter_extreme(
order = vars(ADT),
order = exprs(ADT),
by_vars = subject_keys,
mode = "first",
check_type = "none"
Expand All @@ -305,7 +305,7 @@ derive_param_clinbenefit <- function(dataset,
# without records in ovr_data and rsp_data
new_param <- bind_rows(ovr_data, rsp_data, adsl) %>%
filter_extreme(
order = vars(ADT),
order = exprs(ADT),
by_vars = subject_keys,
mode = "first",
check_type = "none"
Expand Down

0 comments on commit 7cb09ee

Please sign in to comment.