Skip to content

Commit

Permalink
Prepare CRAN release (#863)
Browse files Browse the repository at this point in the history
* Prepare CRAN release

* style docs

* lintr

* trigger CI

* trigger CI

* lintr

* skip test

* skip glmmTMB tests on win-devel

* cran comments [skip ci]

* submitted
  • Loading branch information
strengejacke authored Mar 22, 2024
1 parent 8462ba8 commit dfecd01
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 88 deletions.
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.19.9
Date: 2024-03-15 15:07:43 UTC
SHA: a2cb3065be697a9573a0134258a3fea6c0df3bb9
Version: 0.19.10
Date: 2024-03-21 22:24:25 UTC
SHA: 7d69f543f5aa08eee8d5c69811972278628eba24
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.19.9.2
Version: 0.19.10
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
2 changes: 1 addition & 1 deletion R/clean_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ clean_names.character <- function(x, include_names = FALSE, ...) {
if (grepl("::", x[i], fixed = TRUE)) {
x[i] <- sub("(.*)::(.*)", "\\2", x[i])
}
if (pattern[j] == "offset") {
if (pattern[j] == "offset") { # nolint
x[i] <- trim_ws(unique(sub("^offset\\(([^-+ )]*).*", "\\1", x[i])))
} else if (pattern[j] == "I") {
if (!ignore_asis) x[i] <- trim_ws(unique(sub("I\\(((\\w|\\.)*).*", "\\1", x[i])))
Expand Down
41 changes: 19 additions & 22 deletions R/standardize_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,33 @@
#' the same for any model object.
#'
#' @param data A data frame. In particular, objects from *easystats*
#' package functions like
#' [parameters::model_parameters()] or
#' [effectsize::effectsize()] are accepted, but also
#' data frames returned by `broom::tidy()` are valid objects.
#' package functions like [parameters::model_parameters()] or
#' [effectsize::effectsize()] are accepted, but also data frames returned by
#' `broom::tidy()` are valid objects.
#' @param style Standardization can either be based on the naming conventions
#' from the [easystats-project](https://easystats.github.io/easystats/),
#' or on **broom**'s naming scheme.
#' @param ignore_estimate Logical, if `TRUE`, column names like
#' `"mean"` or `"median"` will *not* be converted to
#' `"Coefficient"` resp. `"estimate"`.
#' from the [easystats-project](https://easystats.github.io/easystats/), or on
#' **broom**'s naming scheme.
#' @param ignore_estimate Logical, if `TRUE`, column names like `"mean"` or
#' `"median"` will *not* be converted to `"Coefficient"` resp. `"estimate"`.
#' @param ... Currently not used.
#'
#' @return A data frame, with standardized column names.
#'
#' @details This method is in particular useful for package developers or users
#' who use, e.g., [`parameters::model_parameters()`] in their own
#' code or functions to retrieve model parameters for further processing. As
#' `model_parameters()` returns a data frame with varying column names
#' (depending on the input), accessing the required information is probably
#' not quite straightforward. In such cases, `standardize_names()` can be
#' used to get consistent, i.e. always the same column names, no matter what
#' kind of model was used in `model_parameters()`.
#' who use, e.g., [`parameters::model_parameters()`] in their own code or
#' functions to retrieve model parameters for further processing. As
#' `model_parameters()` returns a data frame with varying column names
#' (depending on the input), accessing the required information is probably
#' not quite straightforward. In such cases, `standardize_names()` can be
#' used to get consistent, i.e. always the same column names, no matter what
#' kind of model was used in `model_parameters()`.
#'
#' For `style = "broom"`, column names are renamed to match **broom**'s
#' naming scheme, i.e. `Parameter` is renamed to `term`,
#' `Coefficient` becomes `estimate` and so on.
#' For `style = "broom"`, column names are renamed to match **broom**'s
#' naming scheme, i.e. `Parameter` is renamed to `term`, `Coefficient` becomes
#' `estimate` and so on.
#'
#' For `style = "easystats"`, when `data` is an object from
#' `broom::tidy()`, column names are converted from "broom"-style into
#' "easystats"-style.
#' For `style = "easystats"`, when `data` is an object from `broom::tidy()`,
#' column names are converted from "broom"-style into "easystats"-style.
#'
#' @examplesIf require("parameters")
#' model <- lm(mpg ~ wt + cyl, data = mtcars)
Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This release fixes errors related to the latest PROreg- and tidytable-updates.
This release fixes errors related to the latest glmmTMB-updates.
11 changes: 5 additions & 6 deletions man/standardize_column_order.Rd

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

29 changes: 13 additions & 16 deletions man/standardize_names.Rd

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

3 changes: 3 additions & 0 deletions tests/testthat/test-cpglmm.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## FIXME: suddenly fails on CRAN for win-devel?
skip_if(getRversion() > "4.3.3")

skip_if_not_installed("cplm")

# cplm::cpglmm doesn't work
Expand Down
77 changes: 39 additions & 38 deletions tests/testthat/test-get_datagrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ m3 <- lm(hp ~ as.factor(cyl), data = mtcars)
m4 <- lm(hp ~ factor(cyl), data = mtcars)

test_that("get_datagrid - data from models", {
expect_equal(get_datagrid(m1)$cyl, c(4, 6, 8))
expect_equal(get_datagrid(m2)$cyl, c(4, 6, 8))
expect_equal(get_datagrid(m3)$cyl, c(4, 6, 8))
expect_equal(get_datagrid(m4)$cyl, c(4, 6, 8))
expect_identical(get_datagrid(m1)$cyl, c(4, 6, 8))
expect_identical(get_datagrid(m2)$cyl, c(4, 6, 8))
expect_identical(get_datagrid(m3)$cyl, c(4, 6, 8))
expect_identical(get_datagrid(m4)$cyl, c(4, 6, 8))
})

# get_datagrid() preserves all factor levels #695
Expand Down Expand Up @@ -109,37 +109,37 @@ test_that("get_datagrid - data", {
expect_length(get_datagrid(x = iris$Sepal.Length), 10)
expect_length(get_datagrid(x = iris$Sepal.Length, length = 5), 5)
expect_length(get_datagrid(x = iris$Sepal.Length, length = NA), length(unique(iris$Sepal.Length)))
expect_equal(min(get_datagrid(x = iris$Sepal.Length, range = "iqr")), as.numeric(quantile(iris$Sepal.Length, 0.025)))
expect_equal(min(get_datagrid(x = iris$Sepal.Length, range = "hdi")), as.numeric(bayestestR::hdi(iris$Sepal.Length, ci = 0.95, verbose = FALSE))[2])
expect_equal(min(get_datagrid(x = iris$Sepal.Length, range = "eti")), as.numeric(bayestestR::eti(iris$Sepal.Length, ci = 0.95, verbose = FALSE))[2])
expect_identical(min(get_datagrid(x = iris$Sepal.Length, range = "iqr")), as.numeric(quantile(iris$Sepal.Length, 0.025))) # nolint
expect_identical(min(get_datagrid(x = iris$Sepal.Length, range = "hdi")), as.numeric(bayestestR::hdi(iris$Sepal.Length, ci = 0.95, verbose = FALSE))[2]) # nolint
expect_identical(min(get_datagrid(x = iris$Sepal.Length, range = "eti")), as.numeric(bayestestR::eti(iris$Sepal.Length, ci = 0.95, verbose = FALSE))[2]) # nolint
expect_length(get_datagrid(iris$Sepal.Length, at = "c(1, 3, 4)"), 3)
expect_length(get_datagrid(iris$Sepal.Length, at = "A = c(1, 3, 4)"), 3)
expect_length(get_datagrid(iris$Sepal.Length, at = "[1, 3, 4]"), 3)
expect_length(get_datagrid(iris$Sepal.Length, at = "[1, 4]"), 10)
expect_length(get_datagrid(iris$Sepal.Length, range = "sd", length = 10), 10)
expect_equal(as.numeric(get_datagrid(iris$Sepal.Length, range = "sd", length = 3)[2]), mean(iris$Sepal.Length))
expect_equal(as.numeric(get_datagrid(iris$Sepal.Length, range = "mad", length = 4)[2]), median(iris$Sepal.Length))
expect_identical(as.numeric(get_datagrid(iris$Sepal.Length, range = "sd", length = 3)[2]), mean(iris$Sepal.Length))
expect_identical(as.numeric(get_datagrid(iris$Sepal.Length, range = "mad", length = 4)[2]), median(iris$Sepal.Length))

# Dataframes
expect_equal(nrow(get_datagrid(iris, length = 2)), 48)
expect_equal(nrow(get_datagrid(iris, at = "Species", length = 2, numerics = 0)), 3)
expect_equal(nrow(get_datagrid(iris, at = "Sepal.Length", length = 3)), 3)
expect_equal(dim(get_datagrid(iris, at = 1:2, length = 3)), c(9, 5))
expect_equal(dim(get_datagrid(iris, at = 1:2, length = c(3, 2))), c(6, 5))
expect_equal(dim(get_datagrid(iris, at = 1:2, length = c(NA, 2))), c(70, 5))
expect_equal(dim(get_datagrid(iris, at = c("Sepal.Length = c(1, 2)"), length = NA)), c(2, 5))
expect_identical(nrow(get_datagrid(iris, length = 2)), 48L)
expect_identical(nrow(get_datagrid(iris, at = "Species", length = 2, numerics = 0)), 3L)
expect_identical(nrow(get_datagrid(iris, at = "Sepal.Length", length = 3)), 3L)
expect_identical(dim(get_datagrid(iris, at = 1:2, length = 3)), c(9L, 5L))
expect_identical(dim(get_datagrid(iris, at = 1:2, length = c(3, 2))), c(6L, 5L))
expect_identical(dim(get_datagrid(iris, at = 1:2, length = c(NA, 2))), c(70L, 5L))
expect_identical(dim(get_datagrid(iris, at = "Sepal.Length = c(1, 2)", length = NA)), c(2L, 5L))
expect_error(get_datagrid(iris, at = 1:2, length = c(3, 2, 4)))
expect_error(get_datagrid(iris, at = 1:2, length = "yes"))
expect_equal(as.numeric(get_datagrid(iris, at = 1:2, range = c("range", "mad"), length = c(2, 3))[4, "Sepal.Width"]), median(iris$Sepal.Width))
expect_identical(as.numeric(get_datagrid(iris, at = 1:2, range = c("range", "mad"), length = c(2, 3))[4, "Sepal.Width"]), median(iris$Sepal.Width)) # nolint


expect_equal(nrow(get_datagrid(data.frame(
expect_identical(nrow(get_datagrid(data.frame(
X = c("A", "A", "B"),
Y = c(1, 5, 2)
), at = "Y", factors = "mode", length = 5)), 5)
Y = c(1, 5, 2),
stringsAsFactors = FALSE
), at = "Y", factors = "mode", length = 5)), 5L)

expect_equal(nrow(get_datagrid(iris, at = c("Sepal.Length = 3", "Species"))), 3)
expect_equal(nrow(get_datagrid(iris, at = c("Sepal.Length = c(3, 1)", "Species = 'setosa'"))), 2)
expect_identical(nrow(get_datagrid(iris, at = c("Sepal.Length = 3", "Species"))), 3L)
expect_identical(nrow(get_datagrid(iris, at = c("Sepal.Length = c(3, 1)", "Species = 'setosa'"))), 2L)

x1 <- get_datagrid(iris, at = c("Species", "Sepal.Length"), length = 30, preserve_range = TRUE)
expect_identical(dim(x1), c(55L, 5L))
Expand All @@ -155,45 +155,46 @@ test_that("get_datagrid - models", {
"Some package uses `formula.tools::as.character.formula()` which breaks `find_formula()`."
)

skip_if(getRversion() > "4.3.3")
skip_if_not_installed("gamm4")
skip_if_not_installed("glmmTMB")
skip_if_not_installed("mgcv")
skip_if_not_installed("rstanarm")
skip_if_not_installed("TMB")
# GLM
mod <- glm(Petal.Length ~ Petal.Width * Sepal.Length, data = iris)
expect_equal(dim(get_datagrid(mod)), c(100, 2))
expect_identical(dim(get_datagrid(mod)), c(100L, 2L))

mod <- glm(Petal.Length ~ Petal.Width * Species, data = iris)
expect_equal(dim(get_datagrid(mod)), c(10, 2))
expect_identical(dim(get_datagrid(mod)), c(10L, 2L))


# LMER4
mod <- lme4::lmer(Petal.Length ~ Petal.Width + (1 | Species), data = iris)
expect_equal(dim(get_datagrid(mod, include_random = TRUE)), c(10, 2))
expect_equal(unique(get_datagrid(mod, include_random = FALSE)$Species), 0)
expect_identical(dim(get_datagrid(mod, include_random = TRUE)), c(10L, 2L))
expect_identical(unique(get_datagrid(mod, include_random = FALSE)$Species), 0)

# GLMMTMB
skip_on_os("mac") # error: FreeADFunObject
mod <- suppressWarnings(glmmTMB::glmmTMB(Petal.Length ~ Petal.Width + (1 | Species), data = iris))
expect_equal(dim(get_datagrid(mod, include_random = TRUE)), c(10, 2))
expect_equal(unique(get_datagrid(mod, include_random = FALSE)$Species), NA)
expect_identical(dim(get_datagrid(mod, include_random = TRUE)), c(10L, 2L))
expect_identical(unique(get_datagrid(mod, include_random = FALSE)$Species), NA)

# MGCV
mod <- mgcv::gam(Petal.Length ~ Petal.Width + s(Sepal.Length), data = iris)
expect_equal(dim(get_datagrid(mod, include_random = TRUE)), c(100, 2))
expect_equal(dim(get_datagrid(mod, include_smooth = FALSE)), c(10, 1))
expect_equal(dim(get_datagrid(mod, include_smooth = "fixed")), c(10, 2))
expect_identical(dim(get_datagrid(mod, include_random = TRUE)), c(100L, 2L))
expect_identical(dim(get_datagrid(mod, include_smooth = FALSE)), c(10L, 1L))
expect_identical(dim(get_datagrid(mod, include_smooth = "fixed")), c(10L, 2L))

mod <- mgcv::gamm(Petal.Length ~ Petal.Width + s(Sepal.Length), random = list(Species = ~1), data = iris)
expect_equal(dim(get_datagrid(mod, include_random = TRUE)), c(63, 3))
expect_equal(dim(get_datagrid(mod, include_random = FALSE, include_smooth = FALSE)), c(10, 1))
expect_identical(dim(get_datagrid(mod, include_random = TRUE)), c(63L, 3L))
expect_identical(dim(get_datagrid(mod, include_random = FALSE, include_smooth = FALSE)), c(10L, 1L))

# GAMM4
mod <- gamm4::gamm4(Petal.Length ~ Petal.Width + s(Sepal.Length), random = ~ (1 | Species), data = iris)
expect_equal(dim(get_datagrid(mod, include_random = TRUE)), c(63, 3))
expect_equal(dim(get_datagrid(mod, include_random = FALSE, include_smooth = "fixed")), c(10, 2))
expect_equal(dim(get_datagrid(mod, include_random = FALSE, include_smooth = FALSE)), c(10, 1))
expect_identical(dim(get_datagrid(mod, include_random = TRUE)), c(63L, 3L))
expect_identical(dim(get_datagrid(mod, include_random = FALSE, include_smooth = "fixed")), c(10L, 2L))
expect_identical(dim(get_datagrid(mod, include_random = FALSE, include_smooth = FALSE)), c(10L, 1L))

# MGCV, splines with variables, see #678

Expand All @@ -206,7 +207,7 @@ test_that("get_datagrid - models", {


# STAN_GAMM4
mod <- suppressWarnings(rstanarm::stan_gamm4(Petal.Length ~ Petal.Width + s(Sepal.Length), random = ~ (1 | Species), data = iris, iter = 100, chains = 2, refresh = 0))
mod <- suppressWarnings(rstanarm::stan_gamm4(Petal.Length ~ Petal.Width + s(Sepal.Length), random = ~ (1 | Species), data = iris, iter = 100, chains = 2, refresh = 0)) # nolint
expect_identical(dim(get_datagrid(mod, include_random = TRUE)), as.integer(c(63, 3)))
expect_identical(dim(get_datagrid(mod, include_random = FALSE, include_smooth = "fixed")), as.integer(c(10, 2)))
expect_identical(dim(get_datagrid(mod, include_random = FALSE, include_smooth = FALSE)), as.integer(c(10, 1)))
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-get_predicted.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ test_that("MASS::rlm", {
# =========================================================================

test_that("get_predicted - lmerMod", {
skip_if(getRversion() > "4.3.3")
suppressWarnings(skip_if_not_installed("glmmTMB"))
skip_if_not_installed("lme4")
skip_if_not_installed("merTools")
Expand Down Expand Up @@ -290,6 +291,7 @@ test_that("get_predicted - lmerMod (log)", {


test_that("get_predicted - merMod", {
skip_if(getRversion() > "4.3.3")
skip_if_not_installed("lme4")
skip_if_not_installed("glmmTMB")
x <- lme4::glmer(vs ~ am + (1 | cyl), data = mtcars, family = "binomial")
Expand All @@ -312,6 +314,7 @@ test_that("get_predicted - merMod", {


test_that("get_predicted - glmmTMB", {
skip_if(getRversion() > "4.3.3")
skip_if_not_installed("glmmTMB")
x <- glmmTMB::glmmTMB(mpg ~ am + (1 | cyl), data = mtcars)

Expand Down Expand Up @@ -629,6 +632,7 @@ test_that("brms: `type` in ellipsis used to produce the wrong intervals", {


test_that("zero-inflation stuff works", {
skip_if(getRversion() > "4.3.3")
skip_if_not_installed("glmmTMB")
skip_if_not_installed("pscl")

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-get_variance.R
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ test_that("random effects CIs, poly slope", {
})

test_that("fixed effects variance for rank-deficient models, #765", {
skip_if(getRversion() > "4.3.3")
skip_if_not_installed("glmmTMB", minimum_version = "1.1.8")
set.seed(101)
dd <- data.frame(
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-glmmTMB.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
skip_on_os("mac") # error: FreeADFunObject
skip_if_not(getRversion() >= "4.0.0")
skip_if(getRversion() > "4.3.3")
skip_if_not_installed("TMB")
skip_if_not_installed("glmmTMB")

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-is_converged.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ test_that("is_converged", {

skip_on_os("mac") # error: FreeADFunObject
skip_on_cran() ## FIXME: check with win-devel
skip_if(getRversion() > "4.3.3")
skip_if_not_installed("glmmTMB")
skip_if_not_installed("TMB")

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-model_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test_that("get_data", {
expect_identical(as.vector(mf4$Petal.Width), as.vector(mf5$Petal.Width))
})

skip_if(getRversion() > "4.3.3")
data(Salamanders, package = "glmmTMB")
skip_on_os("mac") # error: FreeADFunObject
m <- glmmTMB::glmmTMB(
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-model_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ test_that("bigglm bernoulli", {
})

test_that("glmmTMB bernoulli", {
skip_if(getRversion() > "4.3.3")
skip_if_not_installed("glmmTMB")
data(mtcars)
model <- glmmTMB::glmmTMB(vs ~ disp, data = mtcars, family = binomial())
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-null_model.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
skip_if(getRversion() > "4.3.3")
skip_if_not_installed("glmmTMB")
skip_if_not_installed("lme4")
skip_if_not_installed("TMB")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-spatial.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
skip_if_offline()
skip_if(getRversion() > "4.3.3")
suppressWarnings(skip_if_not_installed("glmmTMB"))
suppressWarnings(skip_if_not_installed("geoR"))
skip_if_not_installed("TMB")
Expand Down

0 comments on commit dfecd01

Please sign in to comment.