Skip to content

Commit

Permalink
Merge pull request #649 from grantmcdermott/main
Browse files Browse the repository at this point in the history
Catch for interacted `fixest::i(f0, i.f2)`
  • Loading branch information
vincentarelbundock authored Sep 26, 2022
2 parents 94b0502 + dedede9 commit 572e53a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ Authors@R:
family = "Hayes",
role = c("rev"),
email = "alexpghayes@gmail.com",
comment = c(ORCID = "0000-0002-4985-5160")))
comment = c(ORCID = "0000-0002-4985-5160")),
person(given = "Grant",
family = "McDermott",
role = c("ctb"),
email = "grantmcd@uoregon.edu",
comment = c(ORCID = "0000-0001-7883-8573")))
Maintainer: Daniel Lüdecke <d.luedecke@uke.de>
Description: A tool to provide an easy, intuitive and consistent
access to information contained in various R models, like model
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

* Fixed issue with column alignment in `export_table()` when the data frame
to print contained unicode-characters longer than 1 byte.
* Correctly extract predictors for `fixest::i(f1, i.f2)` interactions (#649 by
@grantmcdermott).

# insight 0.18.4

Expand Down
4 changes: 4 additions & 0 deletions R/find_predictors.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ find_predictors.fixest <- function(x, flatten = FALSE, ...) {

conditional <- all.vars(stats::formula(x))
conditional <- setdiff(conditional, c(instruments, cluster, find_response(x)))
# Catch for interacted fixest::i(f0, i.f2)
if (any(grepl(", i.", x$fml, fixed = TRUE))) {
conditional <- gsub("^i\\.", "", conditional)
}

l <- compact_list(list(
"conditional" = conditional,
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-fixest.R
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,18 @@ test_that("find_variables with interaction", {
mod <- feols(mpg ~ 0 | carb | vs:cyl ~ am:cyl, data = mtcars)
expect_warning(find_variables(mod), NA)
})


test_that("find_predictors with i(f1, i.f2) interaction", {
aq <- airquality
aq$week <- aq$Day %/% 7 + 1

mod <- feols(Ozone ~ i(Month, i.week), aq, notes = FALSE)
expect_equal(
find_predictors(mod),
list(
conditional = c("Month", "week")
),
ignore_attr = TRUE
)
})

0 comments on commit 572e53a

Please sign in to comment.