Skip to content

Commit 286f0e5

Browse files
committed
updated check_formula() with trt_var
1 parent e428d47 commit 286f0e5

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

R/check_formula.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11

22
#' @keywords internal
33
#'
4-
check_formula <- function(formula, treatment = "trt") {
4+
check_formula <- function(formula, trt_var = NULL) {
55

66
if (!inherits(formula, "formula"))
77
stop("`formula` must be of class 'formula'.")
88

99
terms_labels <- attr(terms(formula), "term.labels")
1010

11-
if (!(treatment %in% terms_labels))
12-
stop(sprintf("Treatment term '%s' is missing in the formula", treatment))
11+
if (!is.null(trt_var)) {
12+
if (!(trt_var %in% terms_labels))
13+
stop(sprintf("Treatment term '%s' is missing in the formula", trt_var))
14+
}
1315

1416
invisible()
1517
}

R/strategy_.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ strategy_maic <- function(formula = NULL,
3232
family = gaussian(link = "identity"),
3333
trt_var = NULL,
3434
R = 1000L) {
35-
check_formula(formula)
35+
check_formula(formula, trt_var)
3636
check_family(family)
3737

3838
if (R <= 0 || R %% 1 != 0) {
@@ -74,7 +74,7 @@ strategy_maic <- function(formula = NULL,
7474
strategy_stc <- function(formula = NULL,
7575
family = gaussian(link = "identity"),
7676
trt_var = NULL) {
77-
check_formula(formula)
77+
check_formula(formula, trt_var)
7878
check_family(family)
7979

8080
args <- list(formula = formula,
@@ -132,7 +132,7 @@ strategy_gcomp_ml <- function(formula = NULL,
132132
rho = NA,
133133
R = 1000L,
134134
N = 1000L) {
135-
check_formula(formula)
135+
check_formula(formula, trt_var)
136136
check_family(family)
137137

138138
if (R <= 0 || R %% 1 != 0) {
@@ -195,7 +195,7 @@ strategy_gcomp_stan <- function(formula = NULL,
195195
trt_var = NULL,
196196
rho = NA,
197197
N = 1000L) {
198-
check_formula(formula)
198+
check_formula(formula, trt_var)
199199
check_family(family)
200200

201201
if (N <= 0 || N %% 1 != 0) {
@@ -225,7 +225,7 @@ strategy_mim <- function(formula = NULL,
225225
trt_var= NULL,
226226
rho = NA,
227227
N = 1000L) {
228-
check_formula(formula)
228+
check_formula(formula, trt_var)
229229
check_family(family)
230230

231231
if (N <= 0 || N %% 1 != 0) {

0 commit comments

Comments
 (0)