Skip to content

Commit

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

* cran comments

* comments

* fix

* fix vctrs issue

* news

* typo

* submitted
  • Loading branch information
strengejacke authored Jun 4, 2024
1 parent 24c23c4 commit 94b3377
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 19 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.11
Date: 2024-05-12 17:57:07 UTC
SHA: b850f730c05480293504a2b81217d9244de20f3e
Version: 0.20.0
Date: 2024-06-03 12:54:55 UTC
SHA: 40c4fbce021ca275d823719e60f74717ff61f33d
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.11.5
Version: 0.20.0
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
11 changes: 9 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# insight 0.19.12
# insight 0.20.0

## Breaking

Expand All @@ -10,6 +10,13 @@
* `get_datagrid()`
* `print_parameters()`

## Bug fixes

* Fixed errors in CRAN checks.

* Fixed issues in `compact_list()` for objects that contained variables of
class `vctrs`.

# insight 0.19.11

## General
Expand All @@ -19,7 +26,7 @@

## Bug fixes

* Fixed issue with `get_data()` for `coxme` models when `source`was set to
* Fixed issue with `get_data()` for `coxme` models when `source` was set to
`"modelframe"`.

# insight 0.19.10
Expand Down
5 changes: 5 additions & 0 deletions R/get_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ get_response.default <- function(x, select = NULL, as_proportion = TRUE, source
!is.matrix(response)) {
response <- as.vector(response)
}

# clear vctr-class attributes
if (inherits(response, "vctrs_vctr")) {
class(response) <- setdiff(class(response), c("haven_labelled", "vctrs_vctr"))
}
response
}

Expand Down
9 changes: 8 additions & 1 deletion R/utils_compact.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
#' compact_list(c(1, NA, NA), remove_na = TRUE)
#' @export
compact_list <- function(x, remove_na = FALSE) {
# remove vctr-class attributes
if (is.data.frame(x)) {
x[] <- lapply(x, function(i) {
class(i) <- setdiff(class(i), c("haven_labelled", "vctrs_vctr"))
i
})
}
if (remove_na) {
x[!sapply(x, function(i) !is_model(i) && !inherits(i, c("Formula", "gFormula")) && (length(i) == 0L || is.null(i) || (length(i) == 1L && is.na(i)) || all(is.na(i)) || any(i == "NULL", na.rm = TRUE)))]
} else {
Expand All @@ -30,5 +37,5 @@ compact_list <- function(x, remove_na = FALSE) {
#'
#' @export
compact_character <- function(x) {
x[!sapply(x, function(i) nchar(i) == 0 || all(is.na(i)) || any(i == "NULL", na.rm = TRUE))]
x[!sapply(x, function(i) !nzchar(i, keepNA = TRUE) || all(is.na(i)) || any(i == "NULL", na.rm = TRUE))]
}
10 changes: 9 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
This release is required for the planned update of the 'parameters' package, which will be released once 'insight' is on CRAN. The 'parameters' update fixes errors in CRAN checks.
This release fixes errors in CRAN checks.

Additionally, in the process of stabilizing the API/user interface for packages
from the 'easystats' project, some argument names were renamed and old names
have been deprecated. This will *not break* downstream dependent packages, however,
reverse-dependency checks will raise warnings. We have already patched all
affected downstream packages and will submit them to CRAN in the next few days,
after the release of 'insight'. Once this release-cycle is complete, all
warnings due to deprecated argument names should be resolved.
30 changes: 19 additions & 11 deletions tests/testthat/test-compact-list.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
test_that("compact_list works as expected", {
expect_equal(compact_list(list(NULL, 1, c(NA, NA))), list(1, c(NA, NA)))
expect_equal(compact_list(c(1, NA, NA)), c(1, NA, NA))
expect_equal(compact_list(list(NULL, 1, list(NULL, NULL))), list(1))
expect_equal(compact_list(c(1, NA, NA), remove_na = TRUE), 1)
expect_equal(compact_list(c(1, 2, 3), remove_na = TRUE), c(1, 2, 3))
expect_equal(compact_list(""), "")
expect_identical(compact_list(list(NULL, 1, c(NA, NA))), list(1, c(NA, NA)))
expect_identical(compact_list(c(1, NA, NA)), c(1, NA, NA))
expect_identical(compact_list(list(NULL, 1, list(NULL, NULL))), list(1))
expect_identical(compact_list(c(1, NA, NA), remove_na = TRUE), 1)
expect_identical(compact_list(c(1, 2, 3), remove_na = TRUE), c(1, 2, 3))
expect_identical(compact_list(""), "")
expect_null(compact_list(NULL))
expect_equal(compact_list(logical(0)), logical(0))
expect_identical(compact_list(logical(0)), logical(0))
})

test_that("compact_list, logical > 1", {
x <- list(a = 1, b = c(1, 2), c = NA)
expect_equal(compact_list(x, remove_na = TRUE), list(a = 1, b = c(1, 2)))
expect_equal(compact_list(x, remove_na = FALSE), list(a = 1, b = c(1, 2), c = NA))
expect_identical(compact_list(x, remove_na = TRUE), list(a = 1, b = c(1, 2)))
expect_identical(compact_list(x, remove_na = FALSE), list(a = 1, b = c(1, 2), c = NA))
x <- list(a = 1, b = c(NA, NA), c = NA)
expect_equal(compact_list(x, remove_na = TRUE), list(a = 1))
expect_equal(compact_list(x, remove_na = FALSE), list(a = 1, b = c(NA, NA), c = NA))
expect_identical(compact_list(x, remove_na = TRUE), list(a = 1))
expect_identical(compact_list(x, remove_na = FALSE), list(a = 1, b = c(NA, NA), c = NA))
})

test_that("compact_list, vctrs", {
data(mtcars)
class(mtcars$mpg) <- c("haven_labelled", "vctrs_vctr", "double")
attr(mtcars$mpg, "labels") <- c(`21` = 21)
out <- compact_list(mtcars)
expect_true(all(vapply(out, class, character(1)) == "numeric"))
})
1 change: 1 addition & 0 deletions tests/testthat/test-fixest.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Currently doesn't work on devel - potential fixest issue?
skip_if(TRUE)

skip_on_os("mac")
Expand Down

0 comments on commit 94b3377

Please sign in to comment.