Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import all functions once in R/gsDesign2-package.R, and remove the pkg:: qualifiers #464

Merged
merged 5 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ importFrom(dplyr,summarize)
importFrom(dplyr,ungroup)
importFrom(gsDesign,gsDesign)
importFrom(gsDesign,sfLDOF)
importFrom(mvtnorm,GenzBretz)
importFrom(stats,pnorm)
importFrom(stats,qnorm)
importFrom(stats,setNames)
importFrom(stats,stepfun)
importFrom(stats,uniroot)
importFrom(survival,Surv)
importFrom(tibble,tibble)
importFrom(utils,tail)
useDynLib(gsDesign2, .registration = TRUE)
2 changes: 0 additions & 2 deletions R/ahr.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@
#' }
#' \if{html}{The contents of this section are shown in PDF user manual only.}
#'
#' @importFrom data.table setDF setDT
#'
#' @export
#'
#' @examples
Expand Down
3 changes: 0 additions & 3 deletions R/ahr_blinded.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
#' }
#' \if{html}{The contents of this section are shown in PDF user manual only.}
#'
#' @importFrom tibble tibble
#' @importFrom survival Surv
#'
#' @export
#'
#' @examples
Expand Down
6 changes: 3 additions & 3 deletions R/as_gt.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ as_gt.gs_design <- function(
)

x <- parts$x %>%
dplyr::group_by(Analysis) %>%
group_by(Analysis) %>%
gt::gt() %>%
gt::tab_spanner(
columns = dplyr::all_of(colname_spannersub),
columns = all_of(colname_spannersub),
label = colname_spanner
) %>%
gt::tab_header(title = parts$title, subtitle = parts$subtitle)
Expand Down Expand Up @@ -409,7 +409,7 @@ gsd_parts <- function(
)

list(
x = dplyr::arrange(x2, Analysis),
x = arrange(x2, Analysis),
title = title, subtitle = subtitle,
footnote = footnote %||% gsd_footnote(method, columns),
alpha = max(filter(x, Bound == bound[1])[[alpha_column]])
Expand Down
2 changes: 1 addition & 1 deletion R/check_arg.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ check_enroll_rate_fail_rate <- function(enroll_rate, fail_rate) {
if ("stratum" %in% colnames(enroll_rate) && "stratum" %in% colnames(fail_rate)) {
strata_enroll <- unique(enroll_rate$stratum)
strata_fail <- unique(fail_rate$stratum)
strata_common <- dplyr::intersect(strata_enroll, strata_fail)
strata_common <- intersect(strata_enroll, strata_fail)

if (sum(strata_common %in% strata_enroll) != length(strata_enroll)) {
stop("The `Strata` column in the input argument `enroll_rate` and `fail_rate` must be the same!")
Expand Down
4 changes: 2 additions & 2 deletions R/define.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ define_enroll_rate <- function(
duration,
rate,
stratum = "All") {
df <- tibble::tibble(
df <- tibble(
stratum = stratum,
duration = duration,
rate = rate
Expand Down Expand Up @@ -117,7 +117,7 @@ define_fail_rate <- function(
dropout_rate,
hr = 1,
stratum = "All") {
df <- tibble::tibble(
df <- tibble(
stratum = stratum,
duration = duration,
fail_rate = fail_rate,
Expand Down
4 changes: 0 additions & 4 deletions R/expected_accural.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
#' }
#' \if{html}{The contents of this section are shown in PDF user manual only.}
#'
#' @importFrom dplyr filter lead
#' @importFrom tibble tibble
#' @importFrom stats stepfun
#'
#' @export
#'
#' @examples
Expand Down
2 changes: 0 additions & 2 deletions R/expected_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#' }
#' }
#'
#' @importFrom stats uniroot
#'
#' @export
#'
#' @examples
Expand Down
4 changes: 1 addition & 3 deletions R/fixed_design_ahr.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
#' and `1 - alpha` otherwise).
#' @param study_duration Study duration.
#'
#' @importFrom dplyr filter
#'
#' @returns A list of design characteristic summary.
#'
#' @export
Expand Down Expand Up @@ -121,7 +119,7 @@ fixed_design_ahr <- function(
analysis_time = study_duration
)
}
ans <- tibble::tibble(
ans <- tibble(
design = "ahr",
n = d$analysis$n,
event = d$analysis$event,
Expand Down
4 changes: 1 addition & 3 deletions R/fixed_design_fh.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#' @param rho test parameter in Fleming-Harrington method.
#' @param gamma test parameter in Fleming-Harrington method.
#'
#' @importFrom dplyr filter
#'
#' @export
#'
#' @rdname fixed_design
Expand Down Expand Up @@ -120,7 +118,7 @@ fixed_design_fh <- function(
analysis_time = study_duration
)
}
ans <- tibble::tibble(
ans <- tibble(
design = "fh",
n = d$analysis$n,
event = d$analysis$event,
Expand Down
2 changes: 1 addition & 1 deletion R/fixed_design_lf.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fixed_design_lf <- function(
rr[, 1]
})
)
ans <- tibble::tibble(
ans <- tibble(
design = "lf",
n = d$n,
event = d$d,
Expand Down
2 changes: 1 addition & 1 deletion R/fixed_design_maxcombo.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fixed_design_maxcombo <- function(
)
}
# get the output of MaxCombo
ans <- tibble::tibble(
ans <- tibble(
design = "maxcombo",
n = d$analysis$n,
event = d$analysis$event,
Expand Down
2 changes: 1 addition & 1 deletion R/fixed_design_mb.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fixed_design_mb <- function(
)
}
# get the output of MB
ans <- tibble::tibble(
ans <- tibble(
design = "mb",
n = d$analysis$n,
event = d$analysis$event,
Expand Down
2 changes: 1 addition & 1 deletion R/fixed_design_milestone.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fixed_design_milestone <- function(
)
}
# get the output of MaxCombo
ans <- tibble::tibble(
ans <- tibble(
design = "milestone",
n = d$analysis$n,
event = d$analysis$event,
Expand Down
12 changes: 6 additions & 6 deletions R/fixed_design_rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,26 @@ fixed_design_rd <- function(
# Generate design ----
if (is.null(power)) {
d <- gs_power_rd(
p_c = tibble::tibble(stratum = "All", rate = p_c),
p_e = tibble::tibble(stratum = "All", rate = p_e),
p_c = tibble(stratum = "All", rate = p_c),
p_e = tibble(stratum = "All", rate = p_e),
ratio = ratio,
upper = gs_b, upar = qnorm(1 - alpha),
lower = gs_b, lpar = -Inf,
n = tibble::tibble(stratum = "All", n = n, analysis = 1),
n = tibble(stratum = "All", n = n, analysis = 1),
rd0 = rd0, weight = "unstratified"
)
} else {
d <- gs_design_rd(
p_c = tibble::tibble(stratum = "All", rate = p_c),
p_e = tibble::tibble(stratum = "All", rate = p_e),
p_c = tibble(stratum = "All", rate = p_c),
p_e = tibble(stratum = "All", rate = p_e),
alpha = alpha, beta = 1 - power, ratio = ratio,
upper = gs_b, upar = qnorm(1 - alpha),
lower = gs_b, lpar = -Inf,
rd0 = rd0, weight = "unstratified"
)
}
# get the output of MaxCombo
ans <- tibble::tibble(
ans <- tibble(
design = "rd",
n = d$analysis$n,
bound = (d$bound %>% filter(bound == "upper"))$z,
Expand Down
2 changes: 1 addition & 1 deletion R/fixed_design_rmst.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fixed_design_rmst <- function(
)
}
# get the output
ans <- tibble::tibble(
ans <- tibble(
design = "rmst",
n = d$analysis$n,
event = d$analysis$event,
Expand Down
13 changes: 10 additions & 3 deletions R/gsDesign2-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

#' @keywords internal
#' @useDynLib gsDesign2, .registration = TRUE
#' @importFrom stats setNames
#' @importFrom data.table ":=" as.data.table copy first last rbindlist setDF
#' setDT setcolorder setorderv
#' @importFrom dplyr "%>%" all_of arrange desc filter full_join group_by lead
#' left_join mutate one_of rename row_number select summarize ungroup
#' @importFrom gsDesign gsDesign sfLDOF
#' @importFrom stats pnorm qnorm setNames stepfun uniroot
yihui marked this conversation as resolved.
Show resolved Hide resolved
#' @importFrom tibble tibble
#' @importFrom utils tail
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I prefer the redundant imports at the top of each function. It gives you a better sense of how widely used a given dependency is, and how reliant any given function is on a particular dependency. I'm fine with going with whatever style the group decides on, but I wanted to note that I view the redundancy as a feature.

#' @importFrom Rcpp sourceCpp
#' @useDynLib gsDesign2, .registration = TRUE
#' @keywords internal
"_PACKAGE"
4 changes: 0 additions & 4 deletions R/gs_design_ahr.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@
#' @details
#' To be added.
#'
#' @importFrom dplyr all_of mutate full_join select arrange desc
#' @importFrom gsDesign gsDesign sfLDOF
#' @importFrom stats qnorm
#'
#' @export
#'
#' @examples
Expand Down
8 changes: 3 additions & 5 deletions R/gs_design_combo.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#'
#' @return A list with input parameters, enrollment rate, analysis, and bound.
#'
#' @importFrom mvtnorm GenzBretz
#'
#' @export
#'
#' @examples
Expand Down Expand Up @@ -267,12 +265,12 @@ gs_design_combo <- function(


out <- db %>%
dplyr::select(
select(
analysis, bound, time, n, event, z,
probability, probability_null
) %>%
dplyr::rename(probability0 = probability_null) %>%
dplyr::mutate(`nominal p` = pnorm(z * (-1)))
rename(probability0 = probability_null) %>%
mutate(`nominal p` = pnorm(z * (-1)))


# get bounds to output
Expand Down
5 changes: 1 addition & 4 deletions R/gs_design_npe.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@
#'
#' @author Keaven Anderson \email{keaven_anderson@@merck.com}
#'
#' @importFrom tibble tibble
#' @importFrom stats qnorm uniroot
#'
#' @export
#'
#' @examples
Expand Down Expand Up @@ -469,7 +466,7 @@ gs_design_npe <- function(
full_join(
ans_h0 %>%
select(analysis, bound, probability) %>%
dplyr::rename(probability0 = probability)
rename(probability0 = probability)
)
)

Expand Down
8 changes: 2 additions & 6 deletions R/gs_design_rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
#' @details
#' To be added.
#'
#' @importFrom gsDesign gsDesign sfLDOF
#' @importFrom stats qnorm
#' @importFrom dplyr mutate select arrange desc
#'
#' @export
#'
#' @examples
Expand Down Expand Up @@ -170,7 +166,7 @@ gs_design_rd <- function(p_c = tibble::tibble(stratum = "All", rate = .2),
x_fix <- gs_info_rd(
p_c = p_c,
p_e = p_e,
n = tibble::tibble(
n = tibble(
analysis = 1,
stratum = p_c$stratum,
n = if (is.null(stratum_prev)) {
Expand All @@ -188,7 +184,7 @@ gs_design_rd <- function(p_c = tibble::tibble(stratum = "All", rate = .2),
x_gs <- gs_info_rd(
p_c = p_c,
p_e = p_e,
n = tibble::tibble(
n = tibble(
analysis = rep(1:k, n_strata),
stratum = rep(p_c$stratum, each = k),
n = if (is.null(stratum_prev)) {
Expand Down
2 changes: 0 additions & 2 deletions R/gs_design_wlr.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#' }
#' \if{html}{The contents of this section are shown in PDF user manual only.}
#'
#' @importFrom dplyr all_of
#'
#' @export
#' @return A list with input parameters, enrollment rate, analysis, and bound.
#'
Expand Down
16 changes: 7 additions & 9 deletions R/gs_info_rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#' theta0 (standardized treatment effect under null hypothesis),
#' and statistical information.
#'
#' @importFrom dplyr group_by left_join mutate select summarize ungroup
#'
#' @export
#'
#' @examples
Expand Down Expand Up @@ -183,13 +181,13 @@ gs_info_rd <- function(
suppressMessages(
tbl <- n %>%
left_join(p_c) %>%
dplyr::rename(p_c = rate) %>%
rename(p_c = rate) %>%
left_join(p_e) %>%
dplyr::rename(p_e = rate) %>%
rename(p_e = rate) %>%
left_join(if ("data.frame" %in% class(rd0)) {
rd0
} else {
tibble::tibble(analysis = 1:n_analysis, rd0 = rd0)
tibble(analysis = 1:n_analysis, rd0 = rd0)
}) %>%
mutate(
n_e = n / (1 + ratio),
Expand Down Expand Up @@ -222,7 +220,7 @@ gs_info_rd <- function(
tbl <- tbl %>%
left_join(
tbl %>%
dplyr::group_by(analysis) %>%
group_by(analysis) %>%
summarize(sum_ss = sum(n_c * n_e / (n_c + n_e)))
) %>%
mutate(weight_per_k_per_s = n_c * n_e / (n_c + n_e) / sum_ss) %>%
Expand All @@ -233,7 +231,7 @@ gs_info_rd <- function(
tbl <- tbl %>%
left_join(
tbl %>%
dplyr::group_by(analysis) %>%
group_by(analysis) %>%
summarize(sum_inv_var_per_s = sum(1 / sigma2_H1_per_k_per_s))
) %>%
mutate(weight_per_k_per_s = 1 / sigma2_H1_per_k_per_s / sum_inv_var_per_s) %>%
Expand All @@ -243,7 +241,7 @@ gs_info_rd <- function(

# Pool the strata together ----
ans <- tbl %>%
dplyr::group_by(analysis) %>%
group_by(analysis) %>%
summarize(
n = sum(n),
rd = sum((p_c - p_e) * d * weight_per_k_per_s),
Expand All @@ -261,7 +259,7 @@ gs_info_rd <- function(
info1 = 1 / sigma2_H1,
info0 = 1 / sigma2_H0
) %>%
dplyr::ungroup() %>%
ungroup() %>%
select(analysis, n, rd, rd0, theta1, theta0, info1, info0)

return(ans)
Expand Down
2 changes: 0 additions & 2 deletions R/gs_info_wlr.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
#' The [expected_time()] function is used to get events and average HR at
#' targeted `analysis_time`.
#'
#' @importFrom utils tail
#'
#' @export
#'
#' @examples
Expand Down
Loading