jacob-long / jtools

Tools for summarizing/visualizing regressions and other helpful stuff
https://jtools.jacob-long.com
GNU General Public License v3.0
162 stars 22 forks source link

redirected from r-lib/rlang :sim_slopes encounters an issue with rlang-package #132

Closed Jendryczko closed 1 month ago

Jendryczko commented 1 year ago

Hello everybody.

I already reported this problem to r-lib/rlang: https://github.com/r-lib/rlang/issues/1529

but I was asked to report it here, so I repeat it:

It seems that there is some sort of compatability issue with the latest version of the interactions-package with the latest version of the rlang-package, and -potentially - also the latest version of R and RStudio. If I run the first example provided for "sim_slopes":

fiti <- lm(Income ~ Frost + Murder * Illiteracy, data = as.data.frame(state.x77)) sim_slopes(model = fiti, pred = Murder, modx = Illiteracy)

I get the following error: Error: ! class must be a character vector, not a list. Backtrace:

interactions::sim_slopes(model = fiti, pred = Murder, modx = Illiteracy)
jtools:::summ.lm(...)
jtools:::do_robust(model, robust, cluster, data, vcov)
jtools::get_robust_se(...)
jtools::stop_wrap(...)
rlang (local) <fn>(class = )

versions: packageVersion('interactions')# ‘1.1.5' packageVersion('rlang')# ‘1.0.6’ packageVersion('jtools')# 2.2.1

R-version: 4.2.2.

RStudio-version: 2022.07.2 Build 576

There already exists a stackoverflow entry for this: https://stackoverflow.com/questions/74720514/interactions-and-rlang-error-class-must-be-a-character-vector-not-a-list

But updating the dependencies for jtools and rlang did not help in my case. Does anybody have any solutions?

jacob-long commented 1 year ago

I've been unable to replicate this, so I'm fairly puzzled. Can you (and any others experiencing the error) give the full output of sessionInfo()?

Jendryczko commented 1 year ago

Thank you for attending to this problem. Here you go:

library(interactions)

Using a fitted model as formula input

fiti <- lm(Income ~ Frost + Murder * Illiteracy, data=as.data.frame(state.x77)) probe_interaction(model = fiti, pred = Murder, modx = Illiteracy, modx.values = "plus-minus") # sessionInfo()

Output:

Error: ! class must be a character vector, not a list. Backtrace:

  1. interactions::probe_interaction(...)
  2. interactions::sim_slopes(...)
  3. jtools:::summ.lm(...)
  4. jtools:::do_robust(model, robust, cluster, data, vcov)
  5. jtools::get_robust_se(...)
  6. jtools::stop_wrap(...)
    1. rlang (local) <fn>(class = )

      # sessionInfo() R version 4.2.2 (2022-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale: [1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8 [4] LC_NUMERIC=C LC_TIME=German_Germany.utf8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] interactions_1.1.5

loaded via a namespace (and not attached): [1] Rcpp_1.0.9 rstudioapi_0.14 magrittr_2.0.3 tidyselect_1.2.0 munsell_0.5.0 colorspace_2.0-3 [7] R6_2.5.1 rlang_1.0.6 fansi_1.0.3 dplyr_1.0.10 tools_4.2.2 grid_4.2.2
[13] gtable_0.3.1 utf8_1.2.2 cli_3.5.0 DBI_1.1.3 digest_0.6.31 assertthat_0.2.1 [19] tibble_3.1.8 lifecycle_1.0.3 crayon_1.5.2 ggplot2_3.4.0 vctrs_0.5.1 jtools_2.2.1
[25] glue_1.6.2 compiler_4.2.2 pander_0.6.5 pillar_1.8.1 generics_0.1.3 scales_1.2.1
[31] pkgconfig_2.0.3

zeileis commented 1 year ago

The problem only occurs if the sandwich package is not installed. Thus, @Jendryczko, a quick fix is to install the sandwich package.

What happens internally is the following:

My guess is that jtools::stop_wrap() needs to handle the class. = FALSE argument correctly , similar to jtools::warn_wrap(). Or possibly the stop_wrap() calls in the packages need to be fixed. @jacob-long, it would be great if you could have a look at this.

Jendryczko commented 1 year ago

Thank you very much @zeileis. You were right, simply installing the sandwich-package (no need to load it with library()) fixed everything. I could swear that when I installed ineractions in older R-versions, sandwich was automatically installed alongside but I may be remembering that wrong.

zeileis commented 1 year ago

Possibly you indicated that you want all dependencies to be installed (and not just the required Depends/Imports). The sandwich package is only a "Suggests" and not an "Imports" dependency.

HUtangge commented 1 year ago

Thank you so much :)