Skip to content

Commit

Permalink
Merge branch 'main' into simplify_clean_names
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke authored Oct 27, 2024
2 parents e0cc28c + e309845 commit 5b7d6af
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
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.99.0
Version: 0.99.0.1
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
60 changes: 37 additions & 23 deletions tests/testthat/test-clean_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ test_that("clean_names", {
expect_identical(clean_names("s(x1, x2, x3)"), "x1, x2, x3")
})


test_that("clean_names, model", {
m_rel1 <- lm(mpg ~ relevel(as.factor(cyl), "8") + gear, data = mtcars)
expect_identical(insight::clean_names(m_rel1), c("mpg", "cyl", "gear"))
Expand All @@ -74,11 +75,35 @@ test_that("clean_names, model", {
expect_identical(insight::clean_names(m_rel2), c("mpg", "cyl", "gear"))
})

skip_on_cran()
skip_if_offline()
skip_if_not_installed("httr2")

test_that("clean_names, multimembership", {
skip_if_not_installed("gamlss")
set.seed(123)
dat <- data.frame(
Y = sample(20:50, 100, replace = TRUE),
date = sample(seq(as.Date("1999/01/01"), as.Date("2000/01/01"), by = "day"), 10),
cont1 = rchisq(100, df = 2),
cont2 = runif(100),
cat1 = sample(LETTERS[1:3], 100, replace = TRUE)
)
junk <- capture.output({
mod1 <- suppressWarnings(gamlss::gamlss(
Y ~ date + scale(cont1) + scale(cont2) + I(scale(cont2)^2) * cat1,
data = dat
))
})
expect_identical(
clean_names(find_terms(mod1)$conditional),
c("date", "cont1", "cont2", "cont2", "cat1")
)
})


test_that("clean_names, multimembership", {
skip_on_cran()
skip_if_offline()
skip_if_not_installed("httr2")

m1 <- suppressWarnings(insight::download_model("brms_mm_1"))
skip_if(is.null(m1))
out <- clean_names(m1)
Expand Down Expand Up @@ -106,25 +131,14 @@ test_that("clean_names, multimembership", {
)
})

skip_if_not_installed("gamlss")

test_that("clean_names, multimembership", {
set.seed(123)
dat <- data.frame(
Y = sample(20:50, 100, replace = TRUE),
date = sample(seq(as.Date("1999/01/01"), as.Date("2000/01/01"), by = "day"), 10),
cont1 = rchisq(100, df = 2),
cont2 = runif(100),
cat1 = sample(LETTERS[1:3], 100, replace = TRUE)
)
junk <- capture.output({
mod1 <- suppressWarnings(gamlss::gamlss(
Y ~ date + scale(cont1) + scale(cont2) + I(scale(cont2)^2) * cat1,
data = dat
))
})
expect_identical(
clean_names(find_terms(mod1)$conditional),
c("date", "cont1", "cont2", "cont2", "cat1")
)
test_that("clean_names, division in I()", {
skip_if_not_installed("betareg")
data("GasolineYield", package = "betareg")
data("FoodExpenditure", package = "betareg")

m1 <- betareg::betareg(yield ~ batch + temp, data = GasolineYield)
m2 <- betareg::betareg(I(food / income) ~ income + persons, data = FoodExpenditure)
expect_identical(clean_names(m1), c("yield", "batch", "temp"))
expect_identical(clean_names(m1), c("food", "income", "persons"))
})

0 comments on commit 5b7d6af

Please sign in to comment.