Skip to content

Commit c0238dc

Browse files
committed
DS-4148 Update assign calls for weighted models
* Remove the assignment of .design to the global environment * Instead assign the design variable to the formula environment so the eval code used with the extractAIC method in survey can find it.
1 parent 723937d commit c0238dc

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

R/regression.R

+2-4
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ fitModel <- function(.formula, .estimation.data, .weights, type, robust.se, subs
11941194
model$df <- NA
11951195
else
11961196
{
1197-
assign(".design", .design, envir=.GlobalEnv)
1197+
assign(".design", .design, environment(.formula))
11981198
aic <- try(extractAIC(model), silent = TRUE)
11991199
if (any("try-error" %in% class(aic)))
12001200
{
@@ -1203,7 +1203,6 @@ fitModel <- function(.formula, .estimation.data, .weights, type, robust.se, subs
12031203
"some aspect of the analysis. ")
12041204
aic <- rep(NA, 2)
12051205
}
1206-
remove(".design", envir=.GlobalEnv)
12071206
model$df <- aic[1]
12081207
model$aic <- aic[2]
12091208
}
@@ -1241,9 +1240,8 @@ fitModel <- function(.formula, .estimation.data, .weights, type, robust.se, subs
12411240
family = poisson()),
12421241
"Quasi-Poisson" = svyglm(.formula, .design, subset = non.outlier.data_GQ9KqD7YOf,
12431242
family = quasipoisson()))
1244-
assign(".design", .design, envir=.GlobalEnv)
1243+
assign(".design", .design, envir = environment(.formula))
12451244
aic <- extractAIC(model)
1246-
remove(".design", envir=.GlobalEnv)
12471245
model$df <- aic[1]
12481246
model$aic <- aic[2]
12491247
}

0 commit comments

Comments
 (0)