Skip to content

Commit

Permalink
Apply styler to all remaining tern code (#833)
Browse files Browse the repository at this point in the history
Closes #832
  • Loading branch information
edelarua authored Feb 21, 2023
1 parent e27cca2 commit a285716
Show file tree
Hide file tree
Showing 29 changed files with 707 additions and 684 deletions.
13 changes: 7 additions & 6 deletions R/abnormal_by_marked.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ NULL
#' )
#'
#' df <- df %>%
#' mutate(abn_dir = factor(case_when(
#' ANRIND == "LOW LOW" ~ "Low",
#' ANRIND == "HIGH HIGH" ~ "High",
#' TRUE ~ ""
#' ),
#' levels = c("Low", "High")
#' mutate(abn_dir = factor(
#' case_when(
#' ANRIND == "LOW LOW" ~ "Low",
#' ANRIND == "HIGH HIGH" ~ "High",
#' TRUE ~ ""
#' ),
#' levels = c("Low", "High")
#' ))
#'
#' # Select only post-baseline records.
Expand Down
1 change: 0 additions & 1 deletion R/abnormal_by_worst_grade_worsen.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ h_adlb_worsen <- function(adlb,

# extract data with worst lab
if (!is.null(worst_flag_high) && !is.null(worst_flag_low)) {

# change H to High, L to Low
adlb_f_h[[direction_var]] <- rep("High", nrow(adlb_f_h))
adlb_f_l[[direction_var]] <- rep("Low", nrow(adlb_f_l))
Expand Down
1 change: 0 additions & 1 deletion R/cox_regression_inter.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' Cox Regression Helper: Interactions
#'
#' @description `r lifecycle::badge("stable")`
Expand Down
2 changes: 1 addition & 1 deletion R/coxph.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ s_cox_multivariate <- function(formula, data,
y <- fit_n_aov(
formula = formula,
data = data,
conf_level = conf_level,
conf_level = conf_level,
pval_method = pval_method,
...
)
Expand Down
805 changes: 403 additions & 402 deletions R/d_pkparam.R

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions R/estimate_proportion.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ s_proportion <- function(df,
p_hat <- mean(rsp)

prop_ci <- switch(method,
"clopper-pearson" = prop_clopper_pearson(rsp, conf_level),
"wilson" = prop_wilson(rsp, conf_level),
"wilsonc" = prop_wilson(rsp, conf_level, correct = TRUE),
"strat_wilson" = prop_strat_wilson(rsp,
strata,
weights,
conf_level,
max_iterations,
correct = FALSE
)$conf_int,
"strat_wilsonc" = prop_strat_wilson(rsp,
strata,
weights,
conf_level,
max_iterations,
correct = TRUE
)$conf_int,
"wald" = prop_wald(rsp, conf_level),
"waldcc" = prop_wald(rsp, conf_level, correct = TRUE),
"agresti-coull" = prop_agresti_coull(rsp, conf_level),
"jeffreys" = prop_jeffreys(rsp, conf_level)
"clopper-pearson" = prop_clopper_pearson(rsp, conf_level),
"wilson" = prop_wilson(rsp, conf_level),
"wilsonc" = prop_wilson(rsp, conf_level, correct = TRUE),
"strat_wilson" = prop_strat_wilson(rsp,
strata,
weights,
conf_level,
max_iterations,
correct = FALSE
)$conf_int,
"strat_wilsonc" = prop_strat_wilson(rsp,
strata,
weights,
conf_level,
max_iterations,
correct = TRUE
)$conf_int,
"wald" = prop_wald(rsp, conf_level),
"waldcc" = prop_wald(rsp, conf_level, correct = TRUE),
"agresti-coull" = prop_agresti_coull(rsp, conf_level),
"jeffreys" = prop_jeffreys(rsp, conf_level)
)

list(
Expand Down
1 change: 0 additions & 1 deletion R/h_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ h_tab_one_biomarker <- function(df,

# If there is any subgroup variables, we extend the layout accordingly.
if ("analysis" %in% df$row_type) {

# Now only continue with the subgroup rows.
lyt <- split_rows_by(
lyt = lyt,
Expand Down
2 changes: 0 additions & 2 deletions R/h_response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ h_odds_ratio_df <- function(rsp, arm, strata_data = NULL, conf_level = 0.95, met
l_df <- split(df_rsp, arm)

if (nrow(l_df[[1]]) > 0 && nrow(l_df[[2]]) > 0) {

# Odds ratio and CI.
result_odds_ratio <- s_odds_ratio(
df = l_df[[2]],
Expand All @@ -206,7 +205,6 @@ h_odds_ratio_df <- function(rsp, arm, strata_data = NULL, conf_level = 0.95, met
)

if (!is.null(method)) {

# Test for difference.
result_test <- s_test_proportion_diff(
df = l_df[[2]],
Expand Down
2 changes: 0 additions & 2 deletions R/h_stack_by_baskets.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ h_stack_by_baskets <- function(df,
keys = c("STUDYID", "USUBJID", "ASTDTM", "AEDECOD", "AESEQ"),
aag_summary = NULL,
na_level = "<Missing>") {

# Use of df_explicit_na() in case the user has not previously used
df <- df_explicit_na(df, na_level = na_level)

Expand Down Expand Up @@ -103,7 +102,6 @@ h_stack_by_baskets <- function(df,
if (all(is.na(df[, baskets]))) { # in case there is no level for the target baskets
df_long <- df[-seq_len(nrow(df)), keys] # we just need an empty dataframe keeping all factor levels
} else {

# Concatenate SMQxxxNAM with corresponding SMQxxxSC
df_cnct <- df[, c(keys, baskets[startsWith(baskets, "CQ")])]

Expand Down
1 change: 0 additions & 1 deletion R/h_survival_duration_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ h_coxph_df <- function(tte, is_event, arm, strata_data = NULL, control = control
l_df <- split(df_tte, arm)

if (nrow(l_df[[1]]) > 0 && nrow(l_df[[2]]) > 0) {

# Hazard ratio and CI.
result <- s_coxph_pairwise(
df = l_df[[2]],
Expand Down
42 changes: 21 additions & 21 deletions R/prop_diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,26 @@ s_proportion_diff <- function(df,
}

y <- switch(method,
"wald" = prop_diff_wald(rsp, grp, conf_level, correct = FALSE),
"waldcc" = prop_diff_wald(rsp, grp, conf_level, correct = TRUE),
"ha" = prop_diff_ha(rsp, grp, conf_level),
"newcombe" = prop_diff_nc(rsp, grp, conf_level, correct = FALSE),
"newcombecc" = prop_diff_nc(rsp, grp, conf_level, correct = TRUE),
"strat_newcombe" = prop_diff_strat_nc(rsp,
grp,
strata,
weights_method,
conf_level,
correct = FALSE
),
"strat_newcombecc" = prop_diff_strat_nc(rsp,
grp,
strata,
weights_method,
conf_level,
correct = TRUE
),
"cmh" = prop_diff_cmh(rsp, grp, strata, conf_level)[c("diff", "diff_ci")]
"wald" = prop_diff_wald(rsp, grp, conf_level, correct = FALSE),
"waldcc" = prop_diff_wald(rsp, grp, conf_level, correct = TRUE),
"ha" = prop_diff_ha(rsp, grp, conf_level),
"newcombe" = prop_diff_nc(rsp, grp, conf_level, correct = FALSE),
"newcombecc" = prop_diff_nc(rsp, grp, conf_level, correct = TRUE),
"strat_newcombe" = prop_diff_strat_nc(rsp,
grp,
strata,
weights_method,
conf_level,
correct = FALSE
),
"strat_newcombecc" = prop_diff_strat_nc(rsp,
grp,
strata,
weights_method,
conf_level,
correct = TRUE
),
"cmh" = prop_diff_cmh(rsp, grp, strata, conf_level)[c("diff", "diff_ci")]
)

y$diff <- y$diff * 100
Expand Down Expand Up @@ -149,7 +149,7 @@ s_proportion_diff <- function(df,
#' @export
a_proportion_diff <- make_afun(
s_proportion_diff,
.formats = c(diff = "xx.x", diff_ci = "(xx.x, xx.x)"),
.formats = c(diff = "xx.x", diff_ci = "(xx.x, xx.x)"),
.indent_mods = c(diff = 0L, diff_ci = 1L)
)

Expand Down
25 changes: 13 additions & 12 deletions R/response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,20 @@ a_response_subgroups <- function(.formats = list(
c("n", "n_rsp", "prop", "n_tot", "or", "ci", "pval")
)

afun_lst <- Map(function(stat, fmt) {
if (stat == "ci") {
function(df, labelstr = "", ...) {
in_rows(.list = combine_vectors(df$lcl, df$ucl), .labels = as.character(df$subgroup), .formats = fmt)
afun_lst <- Map(
function(stat, fmt) {
if (stat == "ci") {
function(df, labelstr = "", ...) {
in_rows(.list = combine_vectors(df$lcl, df$ucl), .labels = as.character(df$subgroup), .formats = fmt)
}
} else {
function(df, labelstr = "", ...) {
in_rows(.list = as.list(df[[stat]]), .labels = as.character(df$subgroup), .formats = fmt)
}
}
} else {
function(df, labelstr = "", ...) {
in_rows(.list = as.list(df[[stat]]), .labels = as.character(df$subgroup), .formats = fmt)
}
}
},
stat = names(.formats),
fmt = .formats
},
stat = names(.formats),
fmt = .formats
)

afun_lst
Expand Down
13 changes: 7 additions & 6 deletions R/rtables_access.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ NULL
#'
#' @export
h_row_first_values <- function(table_row,
col_names = NULL,
col_indices = NULL) {

col_names = NULL,
col_indices = NULL) {
col_indices <- check_names_indices(table_row, col_names, col_indices)
checkmate::assert_integerish(col_indices)
checkmate::assert_subset(col_indices, seq_len(ncol(table_row)))
Expand Down Expand Up @@ -71,7 +70,7 @@ h_row_first_values <- function(table_row,
#' # Using values with integers
#' tree_row_elem <- collect_leaves(tbl[3, ])[[1]]
#' result <- h_row_counts(tree_row_elem)
#' #result
#' # result
#'
#' @export
h_row_counts <- function(table_row,
Expand Down Expand Up @@ -140,8 +139,10 @@ check_names_indices <- function(table_row,
col_indices = NULL) {
if (!is.null(col_names)) {
if (!is.null(col_indices)) {
stop("Inserted both col_names and col_indices when selecting row values. ",
"Please choose one.")
stop(
"Inserted both col_names and col_indices when selecting row values. ",
"Please choose one."
)
}
col_indices <- h_col_indices(table_row, col_names)
}
Expand Down
17 changes: 9 additions & 8 deletions R/summarize_patients_exposure_in_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ summarize_patients_exposure_in_cols <- function(lyt, # nolintr
.labels = c(n_patients = "Patients", sum_exposure = "Person time"),
.indent_mods = NULL,
col_split = TRUE) {
afun_list <- Map(function(stat) {
make_afun(
s_count_patients_sum_exposure,
.stats = stat,
.formats = ifelse(stat == "n_patients", "xx (xx.x%)", "xx")
)
},
stat = .stats
afun_list <- Map(
function(stat) {
make_afun(
s_count_patients_sum_exposure,
.stats = stat,
.formats = ifelse(stat == "n_patients", "xx (xx.x%)", "xx")
)
},
stat = .stats
)

if (col_split) {
Expand Down
41 changes: 21 additions & 20 deletions R/survival_duration_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,28 @@ a_survival_subgroups <- function(.formats = list(
c("n", "n_events", "median", "n_tot", "n_tot_events", "hr", "ci", "pval")
)

afun_lst <- Map(function(stat, fmt) {
if (stat == "ci") {
function(df, labelstr = "", ...) {
in_rows(
.list = combine_vectors(df$lcl, df$ucl),
.labels = as.character(df$subgroup),
.formats = fmt
)
afun_lst <- Map(
function(stat, fmt) {
if (stat == "ci") {
function(df, labelstr = "", ...) {
in_rows(
.list = combine_vectors(df$lcl, df$ucl),
.labels = as.character(df$subgroup),
.formats = fmt
)
}
} else {
function(df, labelstr = "", ...) {
in_rows(
.list = as.list(df[[stat]]),
.labels = as.character(df$subgroup),
.formats = fmt
)
}
}
} else {
function(df, labelstr = "", ...) {
in_rows(
.list = as.list(df[[stat]]),
.labels = as.character(df$subgroup),
.formats = fmt
)
}
}
},
stat = names(.formats),
fmt = .formats
},
stat = names(.formats),
fmt = .formats
)

afun_lst
Expand Down
1 change: 0 additions & 1 deletion R/utils_checkmate.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
NULL

check_list_of_variables <- function(x) {

# drop NULL elements in list
x <- Filter(Negate(is.null), x)

Expand Down
13 changes: 7 additions & 6 deletions man/abnormal_by_marked.Rd

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

2 changes: 1 addition & 1 deletion man/rtables_access.Rd

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

3 changes: 2 additions & 1 deletion tests/testthat/test-coxreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ dta_bladder_raw <- local({
armcd = formatters::with_label(as.factor(rx), "ARM"),
covar1 = formatters::with_label(as.factor(enum), "A Covariate Label"),
covar2 = formatters::with_label(
factor(sample(as.factor(enum)), levels = 1:4, labels = c("F", "F", "M", "M")), "Sex (F/M)"),
factor(sample(as.factor(enum)), levels = 1:4, labels = c("F", "F", "M", "M")), "Sex (F/M)"
),
age = sample(20:60, size = 340, replace = TRUE)
)
)
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-estimate_proportion.R
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,5 @@ testthat::test_that(

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})
}
)
2 changes: 1 addition & 1 deletion tests/testthat/test-fit_rsp_step.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ testthat::test_that("fit_rsp_step works as expected with default options", {
covariates = "AGE",
response = "RSP"
)
suppressWarnings(testthat::expect_warning(result <- fit_rsp_step(
suppressWarnings(testthat::expect_warning(result <- fit_rsp_step(
variables = variables,
data = data
)))
Expand Down
Loading

0 comments on commit a285716

Please sign in to comment.