From c92618226f6d6310050ce16298d4d9da7341381a Mon Sep 17 00:00:00 2001 From: John Blischak Date: Tue, 19 Dec 2023 10:57:49 -0500 Subject: [PATCH] Use data.table for grouped sort in `pw_info()` --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/globals.R | 2 +- R/gs_info_ahr.R | 8 +++----- R/gs_info_rd.R | 1 + R/pw_info.R | 8 +++----- man/gs_info_ahr.Rd | 4 ++-- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1360ab84..730100d4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gsDesign2 Title: Group Sequential Design with Non-Constant Effect -Version: 1.1.0.1 +Version: 1.1.0.2 Authors@R: c( person("Keaven", "Anderson", email = "keaven_anderson@merck.com", role = c("aut")), person("Yilong", "Zhang", email = "elong0527@gmail.com", role = c("aut")), diff --git a/NAMESPACE b/NAMESPACE index 3499cb72..8a5a39ab 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -59,6 +59,7 @@ importFrom(data.table,last) importFrom(data.table,rbindlist) importFrom(data.table,setDF) importFrom(data.table,setDT) +importFrom(data.table,setorderv) importFrom(dplyr,"%>%") importFrom(dplyr,all_of) importFrom(dplyr,arrange) diff --git a/R/globals.R b/R/globals.R index 937ac4da..89957006 100644 --- a/R/globals.R +++ b/R/globals.R @@ -20,7 +20,7 @@ utils::globalVariables( unique( c( # From data.table expressions - ".", + ".", ".SD", # From `ahr()` c("stratum", "rate", "hr", "treatment", "time", "info0", "info"), # From `as_gt.gs_design()` diff --git a/R/gs_info_ahr.R b/R/gs_info_ahr.R index 04526659..59825a4a 100644 --- a/R/gs_info_ahr.R +++ b/R/gs_info_ahr.R @@ -29,7 +29,7 @@ #' @param interval An interval that is presumed to include the time at which #' expected event count is equal to targeted event. #' -#' @return A tibble with columns Analysis, Time, AHR, Events, theta, info, info0. +#' @return A data frame with columns Analysis, Time, AHR, Events, theta, info, info0. #' `info`, and `info0` contain statistical information under H1, H0, respectively. #' For analysis `k`, `Time[k]` is the maximum of `analysis_time[k]` and the #' expected time required to accrue the targeted `event[k]`. @@ -46,7 +46,7 @@ #' \item If analysis_time is specified, calculate average hazard ratio using \code{AHR()}. #' \item If event is specified, calculate average hazard ratio using \code{expected_time()}. #' } -#' \item Return a tibble of Analysis, Time, AHR, Events, theta, info, info0. +#' \item Return a data frame of Analysis, Time, AHR, Events, theta, info, info0. #' } #' } #' \if{html}{The contents of this section are shown in PDF user manual only.} @@ -56,8 +56,6 @@ #' event times. The [expected_time()] function is used to get events and #' average HR at targeted `analysis_time`. #' -#' @importFrom tibble tibble -#' #' @export #' #' @examples @@ -172,6 +170,6 @@ gs_info_ahr <- function( # ----------------------------# # output results # # ----------------------------# - ans <- avehr %>% dplyr::transmute(analysis, time, event, ahr, theta, info, info0) + ans <- avehr[, c("analysis", "time", "event", "ahr", "theta", "info", "info0")] return(ans) } diff --git a/R/gs_info_rd.R b/R/gs_info_rd.R index d665b73a..4f0ac2b8 100644 --- a/R/gs_info_rd.R +++ b/R/gs_info_rd.R @@ -32,6 +32,7 @@ #' theta0 (standardized treatment effect under null hypothesis), #' and statistical information. #' +#' @importFrom dplyr group_by left_join mutate select summarize ungroup #' #' @export #' diff --git a/R/pw_info.R b/R/pw_info.R index 7d78e964..ab37ce74 100644 --- a/R/pw_info.R +++ b/R/pw_info.R @@ -73,7 +73,7 @@ #' \if{html}{The contents of this section are shown in PDF user manual only.} #' #' @importFrom data.table ":=" as.data.table copy first last rbindlist setDF -#' @importFrom dplyr group_by summarize ungroup "%>%" +#' setorderv #' #' @export #' @@ -204,10 +204,8 @@ pw_info <- function( ans <- rbindlist(ans_list) # output the results ans <- ans[, .(time, stratum, t, hr, event, info, info0)] - ans <- ans %>% - group_by(time, stratum) %>% - arrange(t, .by_group = TRUE) %>% - ungroup() + setorderv(ans, cols = c("time", "stratum")) + ans <- ans[order(t), .SD, by = .(time, stratum)] setDF(ans) return(ans) } diff --git a/man/gs_info_ahr.Rd b/man/gs_info_ahr.Rd index a6e25a81..c1f1c03a 100644 --- a/man/gs_info_ahr.Rd +++ b/man/gs_info_ahr.Rd @@ -29,7 +29,7 @@ gs_info_ahr( expected event count is equal to targeted event.} } \value{ -A tibble with columns Analysis, Time, AHR, Events, theta, info, info0. +A data frame with columns Analysis, Time, AHR, Events, theta, info, info0. \code{info}, and \code{info0} contain statistical information under H1, H0, respectively. For analysis \code{k}, \code{Time[k]} is the maximum of \code{analysis_time[k]} and the expected time required to accrue the targeted \code{event[k]}. @@ -56,7 +56,7 @@ average HR at targeted \code{analysis_time}. \item If analysis_time is specified, calculate average hazard ratio using \code{AHR()}. \item If event is specified, calculate average hazard ratio using \code{expected_time()}. } - \item Return a tibble of Analysis, Time, AHR, Events, theta, info, info0. + \item Return a data frame of Analysis, Time, AHR, Events, theta, info, info0. } } \if{html}{The contents of this section are shown in PDF user manual only.}