Skip to content

Commit

Permalink
lintr and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattansb committed Sep 3, 2024
1 parent 9448690 commit d9ab045
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 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: insight
Title: Easy Access to Model Information for Various Model Objects
Version: 0.20.4.001
Version: 0.20.4.1
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
10 changes: 5 additions & 5 deletions R/get_datagrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' for a tutorial on how to create a visualisation matrix using this function.
#' \cr\cr
#' Alternatively, these can also be used to extract the "grid" columns from
#' objects generated by `emmeans` and `marginaleffects`.
#' objects generated by **emmeans** and **marginaleffects**.
#'
#' @param x An object from which to construct the reference grid.
#' @param by Indicates the _focal predictors_ (variables) for the reference grid
Expand Down Expand Up @@ -662,7 +662,7 @@ get_datagrid.datagrid <- get_datagrid.visualisation_matrix
#' @rdname get_datagrid
#' @export
get_datagrid.emmGrid <- function(x, ...) {
suppressWarnings(s <- as.data.frame(x))
suppressWarnings({s <- as.data.frame(x)})

Check warning on line 665 in R/get_datagrid.R

View workflow job for this annotation

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

file=R/get_datagrid.R,line=665,col=20,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line.
# We want all the columns *before* the estimate column
est_col_idx <- which(colnames(s) == attr(s, "estName"))
which_cols <- seq_len(est_col_idx - 1)
Expand All @@ -680,12 +680,12 @@ get_datagrid.emm_list <- function(x, ...) {

all_cols <- Reduce(lapply(res, colnames), f = union)
for (i in seq_len(k)) {
res[[i]][,setdiff(all_cols, colnames(res[[i]]))] <- NA
res[[i]][, setdiff(all_cols, colnames(res[[i]]))] <- NA
}
out <- do.call("rbind", res)

clear_cols <- colnames(out)[sapply(out, Negate(anyNA))] # these should be first
out[,c(clear_cols, setdiff(colnames(out), clear_cols)), drop = FALSE]
out[, c(clear_cols, setdiff(colnames(out), clear_cols)), drop = FALSE]
}

#' @rdname get_datagrid
Expand Down Expand Up @@ -731,7 +731,7 @@ get_datagrid.comparisons <- get_datagrid.slopes
if (is.na(by_expression) && is.data.frame(x)) {
if (is.na(varname)) {
format_error(
"Couldn't find which variable were selected in `by`. Check spelling and specification."
"Couldn't find which variables were selected in `by`. Check spelling and specification."
)
} else {
x <- x[[varname]]
Expand Down
2 changes: 1 addition & 1 deletion man/get_datagrid.Rd

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

18 changes: 9 additions & 9 deletions tests/testthat/test-get_datagrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,16 @@ test_that("get_datagrid - emmeans", {
em3 <- emmeans::emmeans(mod2, ~ cyl | hp, at = list(hp = hp_vals))

res <- get_datagrid(em1)
expect_equal(res, get_datagrid(em2))
expect_equal(res, get_datagrid(em3))
expect_identical(res, get_datagrid(em2))
expect_identical(res, get_datagrid(em3))
expect_s3_class(res, "data.frame")
expect_equal(dim(res), c(6, 2))
expect_identical(dim(res), c(6L, 2L))
expect_true(all(c(4, 6, 8) %in% res[[1]]))
expect_true(all(hp_vals %in% res[[2]]))

res <- get_datagrid(emmeans::contrast(em1, method = "poly", max.degree = 2))
expect_s3_class(res, "data.frame")
expect_equal(dim(res), c(4, 2))
expect_identical(dim(res), c(4L, 2L))
expect_true("contrast" %in% colnames(res))
expect_true(all(c("linear", "quadratic") %in% res[["contrast"]]))
expect_true(all(hp_vals %in% res[["hp"]]))
Expand All @@ -249,10 +249,10 @@ test_that("get_datagrid - emmeans", {
em3 <- emmeans::emmeans(mod2, pairwise ~ cyl | hp, at = list(hp = hp_vals))

res <- get_datagrid(em1)
expect_equal(res, get_datagrid(em2))
expect_equal(res, get_datagrid(em3))
expect_identical(res, get_datagrid(em2))
expect_identical(res, get_datagrid(em3))
expect_s3_class(res, "data.frame")
expect_equal(dim(res), c(12, 3))
expect_identical(dim(res), c(12L, 3L))
expect_true("contrast" %in% colnames(res))
expect_true(anyNA(res[["contrast"]]))
expect_true(all(c(4, 6, 8, NA) %in% res[["cyl"]]))
Expand All @@ -275,13 +275,13 @@ test_that("get_datagrid - marginaleffects", {

res <- get_datagrid(mp1)
expect_s3_class(res, "data.frame")
expect_equal(dim(res), c(6, 2))
expect_identical(dim(res), c(6L, 2L))
expect_true(all(c(4, 6, 8) %in% res[[1]]))
expect_true(all(c(50, 100) %in% res[[2]]))

res2 <- get_datagrid(mp2)
expect_s3_class(res2, "data.frame")
expect_equal(dim(res2), c(6, 2))
expect_identical(dim(res2), c(6L, 2L))
expect_true(all(c(4, 6, 8) %in% res2[[2]]))
expect_true(all(c(50, 100) %in% res2[[1]]))

Expand Down

0 comments on commit d9ab045

Please sign in to comment.