Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 21, 2024
1 parent 5403938 commit 01aca65
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 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: datawizard
Title: Easy Data Wrangling and Statistical Transformations
Version: 0.13.0.12
Version: 0.13.0.13
Authors@R: c(
person("Indrajeet", "Patil", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-1995-6531")),
Expand Down
5 changes: 4 additions & 1 deletion R/standardize.models.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ standardize.default <- function(x,
}

# check model formula. Some notations don't work when standardizing data
insight::formula_ok(x, verbose = verbose)
if (!insight::formula_ok(x, verbose = verbose)) {
insight::format_alert(insight::color_text("Model cannot be standardized.", "red"))
return(x)
}

data_std <- NULL # needed to avoid note
.standardize_models(x,
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-standardize_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ test_that("standardize | errors", {
})


test_that("standardize | problematic formulas", {
data(mtcars)
m <- lm(mpg ~ hp, data = mtcars)
expect_equal(
coef(standardise(m)),
c(`(Intercept)` = -3.14935717633686e-17, hp = -0.776168371826586),
tolerance = 1e-4
)

colnames(mtcars)[1] <- "1_mpg"
m <- lm(`1_mpg` ~ hp, data = mtcars)
expect_message(expect_warning(standardise(m), regex = "Looks like"))

data(mtcars)
m <- lm(mtcars$mpg ~ mtcars$hp)
expect_message(expect_warning(standardise(m), regex = "model formulas"))

m <- lm(mtcars[, 1] ~ hp, data = mtcars)
expect_message(expect_warning(standardise(m), regex = "indexed data"))
})


# Transformations ---------------------------------------------------------
test_that("transformations", {
skip_if_not_installed("effectsize")
Expand Down

0 comments on commit 01aca65

Please sign in to comment.