Skip to content

Commit

Permalink
Don't use native pipe with data.table (requires R >= 4.3.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdblischak committed Feb 22, 2024
1 parent 7904d73 commit e28ef95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BugReports: https://github.com/Merck/simtrial/issues
Encoding: UTF-8
LazyData: true
VignetteBuilder: knitr
Depends: R (>= 4.3.0)
Depends: R (>= 4.1.0)
Imports:
Rcpp,
data.table (>= 1.12.4),
Expand Down
38 changes: 18 additions & 20 deletions R/wlr.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,27 @@ wlr <- function(data, weight){
} else if (inherits(weight, "mb")) {
ans <- data |>
counting_process(arm = "experimental") |>
mb_weight(delay = weight$delay, w_max = weight$w_max) |>
setDT() |>
_[,
.(
s = sum(o_minus_e * mb_weight),
v = sum(var_o_minus_e * mb_weight^2)
)
] |>
_[, .(z = s / sqrt(v))] |>
setDF()
mb_weight(delay = weight$delay, w_max = weight$w_max)
setDT(ans)
ans <- ans[,
.(
s = sum(o_minus_e * mb_weight),
v = sum(var_o_minus_e * mb_weight^2)
)
][, .(z = s / sqrt(v))]
setDF(ans)
} else if (inherits(weight, "early_period")) {
ans <- data |>
counting_process(arm = "experimental") |>
early_zero_weight(early_period = weight$early_period) |>
setDT() |>
_[,
.(
s = sum(o_minus_e * weight),
v = sum(var_o_minus_e * weight^2)
)
] |>
_[, .(z = s / sqrt(v))] |>
setDF()
early_zero_weight(early_period = weight$early_period)
setDT(ans)
ans <- ans[,
.(
s = sum(o_minus_e * weight),
v = sum(var_o_minus_e * weight^2)
)
][, .(z = s / sqrt(v))]
setDF(ans)
}
return(ans)
}

0 comments on commit e28ef95

Please sign in to comment.