Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: see
Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2'
Version: 0.14.0.9
Version: 0.14.0.10
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
21 changes: 10 additions & 11 deletions R/scale_color_colorhex.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,29 +173,28 @@

# Palette --------------------------------------------------------------------

#' Color palettes from <https://www.color-hex.com/>
#' Color palettes from color-hex.com.
#'
#' This function downloads a requested color palette from <https://www.color-hex.com/>.
#' This function downloads a requested color palette from color-hex.com.
#' This website provides a large number of user-submitted color palettes.
#'
#' @note
#' The default [Josiah color palette (number 1014416)](https://www.color-hex.com/color-palette/1014416)
#' is available without an internet connection. All other color palettes require
#' an internet connection to download and access.
#' The default Josiah color palette (number 1014416) is available without an
#' internet connection. All other color palettes require an internet connection
#' to download and access.
#'
#' @param palette The numeric code for a palette at <https://www.color-hex.com/>.
#' For example, `1014416` for the
#' [Josiah color palette (number 1014416)](https://www.color-hex.com/color-palette/1014416).
#' @param palette The numeric code for a palette at color-hex.com. For example,
#' `1014416` for the Josiah color palette (number 1014416).
#' @inheritParams palette_flat
#'
#' @details This function is usually not called directly, but from within
#' [`scale_color_colorhex()`][scale_color_colorhex].
#' [`scale_color_colorhex()`][scale_color_colorhex].
#'
#' @export
palette_colorhex <- function(palette = 1014416, reverse = FALSE, ...) {
if (!is.numeric(palette) && suppressWarnings(is.na(as.numeric(palette)))) {
insight::format_error(
"`palette` must be the numeric code for a color palette at <https://www.color-hex.com/>"
"`palette` must be the numeric code for a color palette at color-hex.com"
)
}

Expand All @@ -205,7 +204,7 @@
} else {
insight::check_if_installed(
"curl",
reason = "to retrieve palettes from <https://www.color-hex.com/>"
reason = "to retrieve palettes from color-hex.com"
)

curl_url <- paste0("https://www.color-hex.com//color-palette/", palette)
Expand Down Expand Up @@ -244,5 +243,5 @@

pal <- grDevices::colorRampPalette(pal, ...)
attr(pal, "name") <- pal_name
return(pal)

Check warning on line 246 in R/scale_color_colorhex.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/scale_color_colorhex.R,line=246,col=3,[return_linter] Use implicit return behavior; explicit return() is not needed.
}
15 changes: 7 additions & 8 deletions man/palette_colorhex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/scale_color_colorhex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
612 changes: 612 additions & 0 deletions tests/testthat/_snaps/check_model_theme/check-model-theme-attr-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
549 changes: 549 additions & 0 deletions tests/testthat/_snaps/check_model_theme/check-model-theme-attr-3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
615 changes: 615 additions & 0 deletions tests/testthat/_snaps/check_model_theme/check-model-theme-attr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
618 changes: 618 additions & 0 deletions tests/testthat/_snaps/check_model_theme/check-model-theme-bw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
549 changes: 549 additions & 0 deletions tests/testthat/_snaps/check_model_theme/check-model-theme-custom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
549 changes: 549 additions & 0 deletions tests/testthat/_snaps/check_model_theme/check-model-theme-minimal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
569 changes: 569 additions & 0 deletions tests/testthat/_snaps/check_model_theme/check-model-without-theme.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
195 changes: 195 additions & 0 deletions tests/testthat/test-check_model_theme.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
skip_on_cran()
skip_if_not_installed("performance")
skip_if_not_installed("ggplot2")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test file uses vdiffr::expect_doppelganger inside the helper function expect_doppelganger_with_seed, but it does not check if the vdiffr package is installed. If vdiffr is missing in the testing environment, the tests will fail with an error instead of being gracefully skipped. Please add skip_if_not_installed("vdiffr") at the top of the file.

skip_if_not_installed("ggplot2")
skip_if_not_installed("vdiffr")

skip_if_not_installed("vdiffr")

expect_doppelganger_with_seed <- function(title, fig, seed = 123) {
set.seed(seed)
vdiffr::expect_doppelganger(title = title, fig = fig)
}

# ==============================================================================
# ISSUE #851: theme argument of performance::check_model() has no effect
# ==============================================================================
#
# These tests document the expected behavior of the theme argument in
# performance::check_model(). Currently, these tests FAIL due to bugs in the see package's
# plot.performance::check_model() function.
#
# Three main problems identified:
# 1. Standard ggplot2 themes cause "unused arguments" errors
# 2. Custom user-defined theme functions cannot be accessed
# 3. Theme attribute not properly read by see package's plot method
#
# The actual fix needs to be implemented in the see package's
# R/plot.performance::check_model.R file (around lines 64-67).
#
# See: https://github.com/easystats/performance/issues/851
# ==============================================================================

# Test 1: Standard ggplot2 themes should work without errors
# -----------------------------------------------------------------------------
# PROBLEM: Currently throws "unused arguments" error because see package passes
# hardcoded arguments (plot.title.space, axis.title.space, etc.) that don't
# exist in standard ggplot2 themes.
test_that("performance::check_model accepts standard ggplot2 themes as functions", {
m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)

# Test with theme_dark passed as function (not string)
# Explicit namespace call for clarity and to avoid conflicts
p1 <- performance::check_model(m, theme = ggplot2::theme_dark())
# The plot method should handle the theme attribute correctly
expect_doppelganger_with_seed(
title = "check_model-theme_attr",
fig = plot(p1)
)

# Test with theme_minimal
p2 <- performance::check_model(m, theme = ggplot2::theme_minimal())
expect_doppelganger_with_seed(
title = "check_model-theme_minimal",
fig = plot(p2)
)

# Test with theme_bw
p3 <- performance::check_model(m, theme = ggplot2::theme_bw())
expect_doppelganger_with_seed(
title = "check_model-theme_bw",
fig = plot(p3)
)
})


# Test 2: Theme as string should work for backward compatibility
# -----------------------------------------------------------------------------
# PROBLEM: String parsing doesn't work reliably, and when it does parse,
# it still hits the "unused arguments" error from hardcoded parameters.
test_that("performance::check_model accepts theme as string (backward compatibility)", {
m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)

# String reference should work
p1 <- performance::check_model(m, theme = "ggplot2::theme_dark")
expect_doppelganger_with_seed(
title = "check_model-theme_dark_string",
fig = plot(p1)
)

# Test with theme_bw as string
p2 <- performance::check_model(m, theme = "ggplot2::theme_bw")
expect_doppelganger_with_seed(
title = "check_model-theme_bw_string",
fig = plot(p2)
)
})


# Test 3: Custom theme functions should work
# -----------------------------------------------------------------------------
# PROBLEM: Custom themes defined in user environment can't be accessed because
# the see package's string parsing approach only searches package namespaces.
test_that("performance::check_model accepts custom theme functions from user environment", {
# Define custom theme in test environment
my_custom_theme <- function(
base_size = 11,
base_family = "",
base_line_size = base_size / 22,
base_rect_size = base_size / 22
) {
ggplot2::theme_minimal(
base_size = base_size,
base_family = base_family,
base_line_size = base_line_size,
base_rect_size = base_rect_size
) +
ggplot2::theme(
plot.title = ggplot2::element_text(size = 16, face = "bold"),
panel.grid.major = ggplot2::element_line(color = "gray80")
)
}

m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)

# Custom theme function should work when passed directly
p1 <- performance::check_model(m, theme = my_custom_theme())
expect_doppelganger_with_seed(
title = "check_model-theme_custom",
fig = plot(p1)
)
})


# Test 4: Theme attribute should be stored and retrieved correctly
# -----------------------------------------------------------------------------
# PROBLEM: The theme attribute is stored by performance::check_model() but may not be
# properly read by see package's plot method.
test_that("theme attribute is stored and used correctly", {
m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)

# Test with function
p1 <- performance::check_model(m, theme = ggplot2::theme_dark())

# Theme should be stored as attribute
expect_true(!is.null(attr(p1, "theme")))

Check warning on line 132 in tests/testthat/test-check_model_theme.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-check_model_theme.R,line=132,col=3,[expect_not_linter] expect_false(x) is better than expect_true(!x), and vice versa.

# Attribute should contain the theme
theme_attr <- attr(p1, "theme")
expect_s3_class(theme_attr, "theme")

# Theme should be applied when plotting
expect_doppelganger_with_seed(
title = "check_model-theme_attr-2",
fig = plot(p1)
)

# Test with string
p2 <- performance::check_model(m, theme = "ggplot2::theme_minimal")
expect_true(!is.null(attr(p2, "theme")))

Check warning on line 146 in tests/testthat/test-check_model_theme.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-check_model_theme.R,line=146,col=3,[expect_not_linter] expect_false(x) is better than expect_true(!x), and vice versa.
expect_identical(attr(p2, "theme"), "ggplot2::theme_minimal")

expect_doppelganger_with_seed(
title = "check_model-theme_attr-3",
fig = plot(p2)
)
})


# Test 5: Default theme should work when no theme specified
# -----------------------------------------------------------------------------
# Tests that performance::check_model works correctly when no theme argument is provided,
# ensuring it falls back to the default theme.
test_that("performance::check_model works without theme argument (default behavior)", {
m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)

# Should work with default theme
p <- performance::check_model(m)
expect_doppelganger_with_seed(
title = "check_model-without_theme",
fig = plot(p)
)

# Default theme should be stored
p <- performance::check_model(m)
expect_true(!is.null(attr(p, "theme")))

Check warning on line 172 in tests/testthat/test-check_model_theme.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-check_model_theme.R,line=172,col=3,[expect_not_linter] expect_false(x) is better than expect_true(!x), and vice versa.
})


# Test 6: theme argument in plot() should override theme from performance::check_model()
# -----------------------------------------------------------------------------
# This tests that the plot method's theme parameter can override the theme
# set during performance::check_model() call.
test_that("plot theme argument overrides performance::check_model theme", {
m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)

# Create with one theme
p <- performance::check_model(m, theme = ggplot2::theme_dark())

# Plot with different theme - should work
expect_doppelganger_with_seed(
title = "check_model-different_theme-1",
fig = plot(p, theme = ggplot2::theme_minimal())
)
expect_doppelganger_with_seed(
title = "check_model-different_theme-2",
fig = plot(p, theme = ggplot2::theme_bw())
)
})
2 changes: 2 additions & 0 deletions tests/testthat/test-plot.check_normality.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
skip_if_not_installed("vdiffr")

test_that("`plot.see_check_normality()` works", {
skip_if_not_installed("lme4")
skip_if_not_installed("qqplotr")

set.seed(123)
m_lm <<- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)

Check warning on line 8 in tests/testthat/test-plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-plot.check_normality.R,line=8,col=8,[assignment_linter] Replace <<- by assigning to a specific environment (with assign() or <-) to avoid hard-to-predict behavior.
result1 <- performance::check_normality(m_lm)
result2 <- performance::check_normality(m_lm)
result3 <- performance::check_normality(m_lm)

set.seed(123)
data(sleepstudy, package = "lme4")
m_lmer <<- lme4::lmer(Reaction ~ Days + (Days | Subject), sleepstudy)

Check warning on line 15 in tests/testthat/test-plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-plot.check_normality.R,line=15,col=10,[assignment_linter] Replace <<- by assigning to a specific environment (with assign() or <-) to avoid hard-to-predict behavior.
result4 <- performance::check_normality(m_lmer, "random")
result5 <- performance::check_normality(m_lmer, "fixed")

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-plot.check_outliers.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("vdiffr")

test_that("`plot.see_check_outliers()` works", {
mt1 <- mtcars[, c(1, 3, 4)]
mt2 <- rbind(
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-plot.compare_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ test_that("`plot()` for compare_parameters", {
skip_if_not_installed("glmmTMB")
skip_if_not_installed("lme4")
skip_if_not_installed("parameters")
skip_if_not_installed("vdiffr")

gdat <- readRDS(system.file(
"vignette_data",
"gophertortoise.rds",
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-plot.effectsize_table.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test_that("`plot.see_effectsize_table()` works", {
skip_if_not_installed("vdiffr")
m <- aov(mpg ~ factor(am) * factor(cyl), data = mtcars)
result <- effectsize::eta_squared(m)
set.seed(123)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-plot.n_factors.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test_that("`plot.see_n_factors()` works", {
skip_if_not_installed("nFactors")
skip_if_not_installed("vdiffr")

result <- parameters::n_factors(datasets::mtcars, type = "PCA")

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-plot.p_direction.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("vdiffr")

test_that("`plot.see_p_direction()` works", {
skip_if_not_installed("rstanarm")
skip_if_not_installed("ggridges")
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-plot.p_significance.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("vdiffr")

test_that("`plot.see_p_significance()` works", {
skip_if_not_installed("rstanarm")
skip_if_not_installed("ggridges")
Expand All @@ -9,8 +11,8 @@ test_that("`plot.see_p_significance()` works", {
})

skip_on_cran()
skip_if_not_installed("bayestestR", minimum_version = "0.14.1")
skip_if_not_installed("parameters", minimum_version = "0.22.3")
skip_if_not_installed("bayestestR")
skip_if_not_installed("parameters")

test_that("`plot.see_p_significance works for two thresholds", {
skip_if_not_installed("ggridges")
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-plot.parameters_model.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("vdiffr")

test_that("`plot.see_parameters_model()` works", {
m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)
result <- parameters::model_parameters(m)
Expand All @@ -20,11 +22,11 @@ test_that("`plot.see_parameters_model()` sort parameter works for fixed effects"
# Test sort = TRUE (should be same as ascending)
p1 <- plot(result, sort = TRUE)
expect_s3_class(p1, "gg")

# Test sort = "ascending"
p2 <- plot(result, sort = "ascending")
expect_s3_class(p2, "gg")

# Test sort = "descending"
p3 <- plot(result, sort = "descending")
expect_s3_class(p3, "gg")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-plot.performance_pp_check.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("vdiffr")

test_that("`print.see_performance_pp_check()` works", {
set.seed(123)
model <- lm(Sepal.Length ~ Species * Petal.Width + Petal.Length, data = iris)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-plot.performance_roc.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test_that("`plot.see_performance_roc()` works", {
skip_if_not_installed("vdiffr")
set.seed(123)
iris$y <- rbinom(nrow(iris), size = 1, 0.3)
folds <- sample(nrow(iris), size = nrow(iris) / 8, replace = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-plot.simulate_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_on_cran()
skip_if_offline()
skip_if_not_installed("mclogit")
skip_if_not_installed("parameters")

skip_if_not_installed("vdiffr")

test_that("`plot()` for simulate_parameters", {
pict <- base::readRDS(url("https://slcladal.github.io/data/pict.rda", "rb"))
Expand Down
Loading
Loading