From d9ab045ec0d895477c71a5512c6bd91fcb833115 Mon Sep 17 00:00:00 2001 From: "Mattan S. Ben-Shachar" Date: Tue, 3 Sep 2024 10:13:10 +0300 Subject: [PATCH] lintr and other fixes --- DESCRIPTION | 2 +- R/get_datagrid.R | 10 +++++----- man/get_datagrid.Rd | 2 +- tests/testthat/test-get_datagrid.R | 18 +++++++++--------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ad4fc4976..9e95c80f0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/R/get_datagrid.R b/R/get_datagrid.R index 8fec20079..32138be67 100644 --- a/R/get_datagrid.R +++ b/R/get_datagrid.R @@ -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 @@ -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)}) # 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) @@ -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 @@ -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]] diff --git a/man/get_datagrid.Rd b/man/get_datagrid.Rd index 6799424f5..3c77d3046 100644 --- a/man/get_datagrid.Rd +++ b/man/get_datagrid.Rd @@ -188,7 +188,7 @@ combined values. Usually used to make generate predictions using 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 \code{emmeans} and \code{marginaleffects}. +objects generated by \strong{emmeans} and \strong{marginaleffects}. } \examples{ \dontshow{if (require("bayestestR", quietly = TRUE) && require("datawizard", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} diff --git a/tests/testthat/test-get_datagrid.R b/tests/testthat/test-get_datagrid.R index a3a89417e..424cc0585 100644 --- a/tests/testthat/test-get_datagrid.R +++ b/tests/testthat/test-get_datagrid.R @@ -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"]])) @@ -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"]])) @@ -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]]))