Skip to content

Commit d33649d

Browse files
Merge pull request #509 from yihui/char-for-fun
Allow bound functions and spending functions to take character values
2 parents 4a05474 + f49e621 commit d33649d

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# gsDesign2 1.1.4
2+
3+
## User interface improvements
4+
5+
- Bound functions and spending functions can be provided through their names (character strings) now, e.g., `gs_design_ahr(..., upper = "gs_spending_bound", upar = list(sf = "sfLDOF", ...))` (#509, thanks to @yihui).
6+
17
# gsDesign2 1.1.3
28

39
## Bug fixes

R/gs_design_ahr.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ gs_design_ahr <- function(
229229
info_frac <- 1
230230
}
231231
info_scale <- match.arg(info_scale)
232+
upper <- match.fun(upper)
233+
lower <- match.fun(lower)
232234

233235
# Check inputs ----
234236
check_analysis_time(analysis_time)
@@ -243,7 +245,7 @@ gs_design_ahr <- function(
243245
# Check if alpha is same as alpha spending ----
244246
if (identical(upper, gs_spending_bound)) {
245247
if (!is.null(upar$total_spend)) {
246-
if (methods::missingArg(alpha)) {
248+
if (missing(alpha)) {
247249
alpha <- upar$total_spend
248250
} else {
249251
if (alpha != upar$total_spend) {

R/gs_design_npe.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ gs_design_npe <- function(
275275
check_theta(theta0, n_analysis)
276276
check_theta(theta1, n_analysis)
277277

278+
upper <- match.fun(upper)
279+
lower <- match.fun(lower)
278280
# check test_upper & test_lower
279281
if (length(test_upper) == 1 && n_analysis > 1) test_upper <- rep(test_upper, n_analysis)
280282
if (length(test_lower) == 1 && n_analysis > 1) test_lower <- rep(test_lower, n_analysis)

R/gs_power_npe.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ gs_power_npe <- function(theta = .1, theta0 = NULL, theta1 = NULL, # 3 theta
243243
} else if (length(theta1) == 1) {
244244
theta1 <- rep(theta1, n_analysis)
245245
}
246+
upper <- match.fun(upper)
247+
lower <- match.fun(lower)
246248
if (length(test_upper) == 1 && n_analysis > 1) test_upper <- rep(test_upper, n_analysis)
247249
if (length(test_lower) == 1 && n_analysis > 1) test_lower <- rep(test_lower, n_analysis)
248250

R/gs_spending_bound.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,13 @@ gs_spending_bound <- function(k = 1,
121121
}
122122

123123
# Compute cumulative spending at each analyses ----
124-
spend <- par$sf(alpha = par$total_spend, t = timing, param = par$param)$spend
124+
if (!is.function(sf <- par$sf)) sf <- tryCatch(match.fun(sf), error = function(e) {
125+
# in case gsDesign is not attached (i.e. library(gsDesign)) or the spending
126+
# function is not imported into gsDesign2 from gsDesign, we will get it from
127+
# gsDesign's namespace
128+
getExportedValue('gsDesign', sf)
129+
})
130+
spend <- sf(alpha = par$total_spend, t = timing, param = par$param)$spend
125131

126132
# Compute incremental spending at each analyses ----
127133
old_spend <- 0

0 commit comments

Comments
 (0)