Skip to content

Commit

Permalink
Apply Nan's code improvement suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jdblischak committed Feb 23, 2024
1 parent e1b35d1 commit e4dc1af
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/maxcombo.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ maxcombo <- function(data, test1, test2, ...){
rho_vector <- NULL
gamma_vector <- NULL

for (i in 1:n_test) {
for (i in seq_len(n_test)) {
test_i <- get(paste0("test", i))
rho_vector <- c(rho_vector, test_i$rho)
gamma_vector <- c(gamma_vector, test_i$gamma)
Expand Down
4 changes: 2 additions & 2 deletions R/sim_gs_n.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ sim_gs_n <- function(

# simulate for n_sim times
ans <- NULL
for (sim_id in 1:n_sim) {
for (sim_id in seq_len(n_sim)) {
set.seed(seed + sim_id)
# generate data
simu_data <- sim_pw_surv(
Expand All @@ -210,7 +210,7 @@ sim_gs_n <- function(
cut_date <- rep(-100, n_analysis)
ans_1sim <- NULL

for (i_analysis in 1:n_analysis) {
for (i_analysis in seq_len(n_analysis)) {

# get cut date
cut_date[i_analysis] <- cutting[[i_analysis]](data = simu_data)
Expand Down
6 changes: 3 additions & 3 deletions R/wlr.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
#'
wlr <- function(data, weight){

if ("fh" %in% class(weight)) {
if (inherits(weight, "fh")) {
ans <- data |>
counting_process(arm = "experimental") |>
fh_weight(rho_gamma = data.frame(rho = weight$rho, gamma = weight$gamma))

} else if ("mb" %in% class(weight)) {
} else if (inherits(weight, "mb")) {
ans <- data |>
counting_process(arm = "experimental") |>
mb_weight(delay = weight$delay, w_max = weight$w_max) |>
Expand All @@ -52,7 +52,7 @@ wlr <- function(data, weight){
v = sum(var_o_minus_e * mb_weight^2),
z = s / sqrt(v)) |>
dplyr::select(z)
} else if ("early_period" %in% class(weight)){
} else if (inherits(weight, "early_period")) {
ans <- data |>
counting_process(arm = "experimental") |>
early_zero_weight(early_period = weight$early_period) |>
Expand Down
12 changes: 3 additions & 9 deletions R/wlr_weight.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
#' @examples
#' fh(rho = 0, gamma = 0.5)
fh <- function(rho = 0, gamma = 0){
ans <- list(rho = rho, gamma = gamma)
class(ans) <- c(class(ans), "fh", "wlr")
return(ans)
structure(list(rho = rho, gamma = gamma), class = c("list", "fh", "wlr"))
}

#' Magirr and Burman weighting function
Expand All @@ -45,9 +43,7 @@ fh <- function(rho = 0, gamma = 0){
#' @examples
#' mb(delay = 6, w_max = 2)
mb <- function(delay = 4, w_max = Inf){
ans <- list(delay = delay, w_max = w_max)
class(ans) <- c(class(ans), "mb", "wlr")
return(ans)
structure(list(delay = delay, w_max = w_max), class = c("list", "mb", "wlr"))
}

#' Zero early weighting function
Expand All @@ -64,7 +60,5 @@ mb <- function(delay = 4, w_max = Inf){
#' @examples
#' early_zero(6)
early_zero <- function(early_period){
ans <- list(early_period = early_period)
class(ans) <- c(class(ans), "early_period", "wlr")
return(ans)
structure(list(early_period = early_period), class = c("list", "early_period", "wlr"))
}

0 comments on commit e4dc1af

Please sign in to comment.