diff --git a/DESCRIPTION b/DESCRIPTION index ba821b0ba..2325c062d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "patilindrajeet.science@gmail.com", role = "aut", comment = c(ORCID = "0000-0003-1995-6531")), diff --git a/R/standardize.models.R b/R/standardize.models.R index 923c2a65d..be76c5900 100644 --- a/R/standardize.models.R +++ b/R/standardize.models.R @@ -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, diff --git a/tests/testthat/test-standardize_models.R b/tests/testthat/test-standardize_models.R index 706a4e6e7..96a0b12af 100644 --- a/tests/testthat/test-standardize_models.R +++ b/tests/testthat/test-standardize_models.R @@ -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")