Skip to content

Commit 798e3fa

Browse files
committed
fix infinite loop
1 parent eb56f4d commit 798e3fa

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

R/find_formula.R

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ formula_ok <- function(x,
164164
#' @rdname find_formula
165165
#' @export
166166
find_formula.default <- function(x, verbose = TRUE, ...) {
167-
f <- .safe(list(conditional = .dot_formula(stats::formula(x), x)))
167+
f <- .safe(list(conditional = .dot_formula(stats::formula(x), x, ...)))
168168
.find_formula_return(f, verbose = verbose)
169169
}
170170

@@ -1141,7 +1141,7 @@ find_formula.tobit <- function(x, verbose = TRUE, ...) {
11411141

11421142
#' @export
11431143
find_formula.hurdle <- function(x, verbose = TRUE, ...) {
1144-
.zeroinf_formula(x, verbose = verbose)
1144+
.zeroinf_formula(x, verbose = verbose, ...)
11451145
}
11461146

11471147
#' @export
@@ -1153,7 +1153,7 @@ find_formula.zerotrunc <- find_formula.hurdle
11531153

11541154
#' @export
11551155
find_formula.zcpglm <- function(x, verbose = TRUE, ...) {
1156-
.zeroinf_formula(x, separator = "\\|\\|", verbose = verbose)
1156+
.zeroinf_formula(x, separator = "\\|\\|", verbose = verbose, ...)
11571157
}
11581158

11591159

@@ -1742,7 +1742,7 @@ find_formula.model_fit <- function(x, verbose = TRUE, ...) {
17421742

17431743
# Find formula for zero-inflated regressions, where
17441744
# zero-inflated part is separated by | from count part
1745-
.zeroinf_formula <- function(x, separator = "\\|", verbose = TRUE) {
1745+
.zeroinf_formula <- function(x, separator = "\\|", verbose = TRUE, ...) {
17461746
f <- tryCatch(stats::formula(x), error = function(x) NULL)
17471747

17481748
if (is.null(f)) {
@@ -1761,7 +1761,7 @@ find_formula.model_fit <- function(x, verbose = TRUE, ...) {
17611761
## TODO could be extended to all find_formula()
17621762

17631763
# fix dot-formulas
1764-
c.form <- .dot_formula(f = c.form, model = x)
1764+
c.form <- .dot_formula(f = c.form, model = x, ...)
17651765

17661766
# fix dot-formulas
17671767
zi.form <- tryCatch(
@@ -1786,7 +1786,13 @@ find_formula.model_fit <- function(x, verbose = TRUE, ...) {
17861786

17871787
# try to guess "full" formula for dot-abbreviation, e.g.
17881788
# lm(mpg ~., data = mtcars)
1789-
.dot_formula <- function(f, model) {
1789+
.dot_formula <- function(f, model, ...) {
1790+
# skip_dot_formula = TRUE is only internally used, to avoid infinite loops
1791+
# when `find_formula()` is called from `get_data()`
1792+
if (isTRUE(list(...)$skip_dot_formula)) {
1793+
return(f)
1794+
}
1795+
17901796
# fix dot-formulas
17911797
tryCatch(
17921798
{

R/get_data.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ get_data <- function(x, ...) {
240240
# second, try to extract formula directly
241241
if (is.null(dat)) {
242242
dat <- .safe(eval(model_call$data,
243-
envir = environment(find_formula(x, verbose = FALSE)$conditional),
243+
# skip_dot_formula = TRUE is only internally used, to avoid infinite loops
244+
envir = environment(find_formula(x, verbose = FALSE, skip_dot_formula = TRUE)$conditional),
244245
enclos = NULL
245246
))
246247
}

tests/testthat/test-htest.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ test_that("get_data.freedman", {
221221
test_that("model_info.shapiro-test", {
222222
expect_true(model_info(m)$is_variancetest)
223223
expect_identical(model_info(m)$family, "shapiro")
224+
expect_silent(model_info(m))
224225
})
225226

226227

0 commit comments

Comments
 (0)