Skip to content

Commit

Permalink
ellipses_info() doesn't work with do.call()
Browse files Browse the repository at this point in the history
Fixes #778
  • Loading branch information
strengejacke committed Jul 24, 2024
1 parent 14c99f0 commit 7c31725
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: insight
Title: Easy Access to Model Information for Various Model Objects
Version: 0.20.2.7
Version: 0.20.2.9
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* Fixed issue in `get_modelmatrix()` for models from package *brms* with
special functions in the formula (like `mo()`).

* Fixed issue in `ellipses_info()` when this function was called from `do.call()`.

# insight 0.20.2

## New supported models
Expand Down
19 changes: 19 additions & 0 deletions R/ellipsis_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ ellipsis_info.default <- function(..., only_models = TRUE, verbose = TRUE) {
# Create list with names
model_objects <- list(...)
object_names <- match.call(expand.dots = FALSE)[["..."]]
# fix names - if "..." is a list of models, the name is of type "language"
# and we coerce to character here
object_names <- lapply(object_names, function(i) {
if (is.language(i)) {
safe_deparse(i)
} else {
# all other classes are unchanged
i
}
})
# now check if we have character names. If `ellipses_info()` is called
# via `do.call()`, we have the model objects instead of their names (see #778)
# and we then use fixed names
if (!all(vapply(object_names, is.character, logical(1)))) {
object_names <- paste0("model", seq_along(model_objects))
} else if (is.list(object_names)) {
# convert list of characters into regular character vector
object_names <- unlist(object_names, use.names = FALSE)
}
names(model_objects) <- object_names

# If only one object was provided, check if it is a list of models, like "list(m1, m2)"
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-ellipses_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,22 @@ test_that("ellipses_info, random effects", {
expect_true(attributes(info)$re_nested_increasing)
expect_true(attributes(info)$re_nested_decreasing)
})

test_that("ellipses_info, do.call", {
data(iris)
lm1 <- lm(Sepal.Length ~ Species, data = iris)
lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
lm3 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)

out <- do.call(ellipsis_info, list(lm1, lm2, lm3, only_models = TRUE))
expect_length(out, 3)
expect_named(out, c("model1", "model2", "model3"))

out <- ellipsis_info(list(lm1, lm2, lm3), only_models = TRUE)
expect_length(out, 3)
expect_named(out, c("lm1", "lm2", "lm3"))

out <- ellipsis_info(lm1, lm2, lm3, only_models = TRUE)
expect_length(out, 3)
expect_named(out, c("lm1", "lm2", "lm3"))
})

0 comments on commit 7c31725

Please sign in to comment.