Package GWmodel fails to load

418 Views Asked by At

Version 2.2-9 of GWmodel (installed from CRAN) fails to load. Reinstalling the package does not fix the problem either. I also tried detaching all loaded packages and tried loading the package again but it fails. I guess the issue is related to how packages spacetime (STFDF-class function) and raster (RasterBrick function) are being loaded by GWmodel. I tried searching the issue on Github and most of the issues are related to the gstat package and there doesn't seem to be a clear solution for this problem.

detachAllPackages <- function() {

  basic.packages <- c("package:stats","package:graphics","package:grDevices","package:utils","package:datasets","package:methods","package:base")

  package.list <- search()[ifelse(unlist(gregexpr("package:",search()))==1,TRUE,FALSE)]

  package.list <- setdiff(package.list,basic.packages)

  if (length(package.list)>0)  for (package in package.list) detach(package, character.only=TRUE)

}

detachAllPackages()

How can I fix this?

Error:

Error: package or namespace load failed for ‘GWmodel’:
 package slot missing from signature for generic ‘coerce’
and classes STFDF, RasterBrick
cannot use with duplicate class names (the package may need to be re-installed)

Session info:

─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.1 (2022-06-23 ucrt)
 os       Windows 10 x64 (build 22000)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       America/New_York
 date     2022-09-12
 rstudio  2022.07.1+554 Spotted Wakerobin (desktop)
 pandoc   2.18 @ C:/Program Files/RStudio/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package           * version  date (UTC) lib source
 abind             * 1.4-5    2016-07-21 [1] CRAN (R 4.2.0)
 assertthat          0.2.1    2019-03-21 [1] CRAN (R 4.2.1)
 backports           1.4.1    2021-12-13 [1] CRAN (R 4.2.0)
 bitops              1.0-7    2021-04-24 [1] CRAN (R 4.2.0)
 boot                1.3-28   2021-05-03 [1] CRAN (R 4.2.1)
 broom               1.0.0    2022-07-01 [1] CRAN (R 4.2.1)
 cachem              1.0.6    2021-08-19 [1] CRAN (R 4.2.1)
 callr               3.7.1    2022-07-13 [1] CRAN (R 4.2.1)
 car                 3.1-0    2022-06-15 [1] CRAN (R 4.2.1)
 carData             3.0-5    2022-01-06 [1] CRAN (R 4.2.1)
 cellranger          1.1.0    2016-07-27 [1] CRAN (R 4.2.1)
 class               7.3-20   2022-01-16 [1] CRAN (R 4.2.1)
 classInt            0.4-7    2022-06-10 [1] CRAN (R 4.2.1)
 cli                 3.3.0    2022-04-25 [1] CRAN (R 4.2.1)
 cluster             2.1.3    2022-03-28 [1] CRAN (R 4.2.1)
 coda                0.19-4   2020-09-30 [1] CRAN (R 4.2.1)
 codetools           0.2-18   2020-11-04 [1] CRAN (R 4.2.1)
 colorspace          2.0-3    2022-02-21 [1] CRAN (R 4.2.1)
 cowplot           * 1.1.1    2020-12-30 [1] CRAN (R 4.2.1)
 crayon              1.5.1    2022-03-26 [1] CRAN (R 4.2.1)
 crosstalk           1.2.0    2021-11-04 [1] CRAN (R 4.2.1)
 curl                4.3.2    2021-06-23 [1] CRAN (R 4.2.1)
 data.table          1.14.2   2021-09-27 [1] CRAN (R 4.2.1)
 DBI                 1.1.3    2022-06-18 [1] CRAN (R 4.2.1)
 dbplyr              2.2.1    2022-06-27 [1] CRAN (R 4.2.1)
 deldir              1.0-6    2021-10-23 [1] CRAN (R 4.2.0)
 DEoptimR            1.0-11   2022-04-03 [1] CRAN (R 4.2.0)
 devtools          * 2.4.4    2022-07-20 [1] CRAN (R 4.2.1)
 digest              0.6.29   2021-12-01 [1] CRAN (R 4.2.1)
 dplyr             * 1.0.9    2022-04-28 [1] CRAN (R 4.2.1)
 e1071               1.7-11   2022-06-07 [1] CRAN (R 4.2.1)
 ellipsis            0.3.2    2021-04-29 [1] CRAN (R 4.2.1)
 evaluate            0.16     2022-08-09 [1] CRAN (R 4.2.1)
 expm                0.999-6  2021-01-13 [1] CRAN (R 4.2.1)
 fansi               1.0.3    2022-03-24 [1] CRAN (R 4.2.1)
 farver              2.1.1    2022-07-06 [1] CRAN (R 4.2.1)
 fastmap             1.1.0    2021-01-25 [1] CRAN (R 4.2.1)
 forcats           * 0.5.1    2021-01-27 [1] CRAN (R 4.2.1)
 forecast            8.16     2022-01-10 [1] CRAN (R 4.2.1)
 foreign             0.8-82   2022-01-16 [1] CRAN (R 4.2.1)
 fracdiff            1.5-1    2020-01-24 [1] CRAN (R 4.2.1)
 fs                  1.5.2    2021-12-08 [1] CRAN (R 4.2.1)
 gargle              1.2.0    2021-07-02 [1] CRAN (R 4.2.1)
 gdata               2.18.0.1 2022-05-10 [1] CRAN (R 4.2.1)
 generics            0.1.3    2022-07-05 [1] CRAN (R 4.2.1)
 ggmap             * 3.0.0    2019-02-05 [1] CRAN (R 4.2.1)
 ggplot2           * 3.3.6    2022-05-03 [1] CRAN (R 4.2.1)
 ggpubr            * 0.4.0    2020-06-27 [1] CRAN (R 4.2.1)
 ggsignif            0.6.3    2021-09-09 [1] CRAN (R 4.2.1)
 glue                1.6.2    2022-02-24 [1] CRAN (R 4.2.1)
 gmodels             2.18.1.1 2022-05-17 [1] CRAN (R 4.2.1)
 googledrive         2.0.0    2021-07-08 [1] CRAN (R 4.2.1)
 googlesheets4       1.0.0    2021-07-21 [1] CRAN (R 4.2.1)
 gridExtra         * 2.3      2017-09-09 [1] CRAN (R 4.2.1)
 gtable              0.3.0    2019-03-25 [1] CRAN (R 4.2.1)
 gtools              3.9.3    2022-07-11 [1] CRAN (R 4.2.1)
 haven               2.5.0    2022-04-15 [1] CRAN (R 4.2.1)
 hms                 1.1.1    2021-09-26 [1] CRAN (R 4.2.1)
 htmltools         * 0.5.3    2022-07-18 [1] CRAN (R 4.2.1)
 htmlwidgets       * 1.5.4    2021-09-08 [1] CRAN (R 4.2.1)
 httpuv              1.6.5    2022-01-05 [1] CRAN (R 4.2.1)
 httr                1.4.3    2022-05-04 [1] CRAN (R 4.2.1)
 intervals           0.15.2   2020-04-04 [1] CRAN (R 4.2.0)
 jpeg                0.1-9    2021-07-24 [1] CRAN (R 4.2.0)
 jsonlite            1.8.0    2022-02-22 [1] CRAN (R 4.2.1)
 KernSmooth          2.23-20  2021-05-03 [1] CRAN (R 4.2.1)
 knitr               1.40     2022-08-24 [1] CRAN (R 4.2.1)
 labeling            0.4.2    2020-10-20 [1] CRAN (R 4.2.0)
 later               1.3.0    2021-08-18 [1] CRAN (R 4.2.1)
 lattice             0.20-45  2021-09-22 [1] CRAN (R 4.2.1)
 lazyeval            0.2.2    2019-03-15 [1] CRAN (R 4.2.1)
 leaflet           * 2.1.1    2022-03-23 [1] CRAN (R 4.2.1)
 leaflet.providers   1.9.0    2019-11-09 [1] CRAN (R 4.2.1)
 LearnBayes          2.15.1   2018-03-18 [1] CRAN (R 4.2.0)
 lifecycle           1.0.1    2021-09-24 [1] CRAN (R 4.2.1)
 lmtest              0.9-40   2022-03-21 [1] CRAN (R 4.2.1)
 lubridate           1.8.0    2021-10-07 [1] CRAN (R 4.2.1)
 lwgeom              0.2-8    2021-10-06 [1] CRAN (R 4.2.1)
 magrittr            2.0.3    2022-03-30 [1] CRAN (R 4.2.1)
 maptools          * 1.1-4    2022-04-17 [1] CRAN (R 4.2.1)
 MASS                7.3-57   2022-04-22 [1] CRAN (R 4.2.1)
 Matrix            * 1.4-1    2022-03-23 [1] CRAN (R 4.2.1)
 memoise             2.0.1    2021-11-26 [1] CRAN (R 4.2.1)
 mgcv                1.8-40   2022-03-29 [1] CRAN (R 4.2.1)
 mime                0.12     2021-09-28 [1] CRAN (R 4.2.0)
 miniUI              0.1.1.1  2018-05-18 [1] CRAN (R 4.2.1)
 modelr              0.1.8    2020-05-19 [1] CRAN (R 4.2.1)
 munsell             0.5.0    2018-06-12 [1] CRAN (R 4.2.1)
 nlme                3.1-157  2022-03-25 [1] CRAN (R 4.2.1)
 nnet                7.3-17   2022-01-16 [1] CRAN (R 4.2.1)
 patchwork         * 1.1.1    2020-12-17 [1] CRAN (R 4.2.1)
 pillar              1.8.0    2022-07-18 [1] CRAN (R 4.2.1)
 pkgbuild            1.3.1    2021-12-20 [1] CRAN (R 4.2.1)
 pkgconfig           2.0.3    2019-09-22 [1] CRAN (R 4.2.1)
 pkgload             1.3.0    2022-06-27 [1] CRAN (R 4.2.1)
 plotly            * 4.10.0   2021-10-09 [1] CRAN (R 4.2.1)
 plyr                1.8.7    2022-03-24 [1] CRAN (R 4.2.1)
 png                 0.1-7    2013-12-03 [1] CRAN (R 4.2.0)
 prettyunits         1.1.1    2020-01-24 [1] CRAN (R 4.2.1)
 prism             * 0.2.0    2020-12-05 [1] CRAN (R 4.2.1)
 processx            3.7.0    2022-07-07 [1] CRAN (R 4.2.1)
 profvis             0.3.7    2020-11-02 [1] CRAN (R 4.2.1)
 promises            1.2.0.1  2021-02-11 [1] CRAN (R 4.2.1)
 proxy               0.4-27   2022-06-09 [1] CRAN (R 4.2.1)
 ps                  1.7.1    2022-06-18 [1] CRAN (R 4.2.1)
 purrr             * 0.3.4    2020-04-17 [1] CRAN (R 4.2.1)
 quadprog            1.5-8    2019-11-20 [1] CRAN (R 4.2.0)
 quantmod            0.4.20   2022-04-29 [1] CRAN (R 4.2.1)
 R6                  2.5.1    2021-08-19 [1] CRAN (R 4.2.1)
 randomcoloR       * 1.1.0.1  2019-11-24 [1] CRAN (R 4.2.1)
 raster            * 3.5-29   2022-08-14 [1] CRAN (R 4.2.1)
 RColorBrewer      * 1.1-3    2022-04-03 [1] CRAN (R 4.2.0)
 Rcpp              * 1.0.9    2022-07-08 [1] CRAN (R 4.2.1)
 readr             * 2.1.2    2022-01-30 [1] CRAN (R 4.2.1)
 readxl              1.4.0    2022-03-28 [1] CRAN (R 4.2.1)
 remotes             2.4.2    2021-11-30 [1] CRAN (R 4.2.1)
 reprex              2.0.1    2021-08-05 [1] CRAN (R 4.2.1)
 reshape2          * 1.4.4    2020-04-09 [1] CRAN (R 4.2.1)
 rgdal             * 1.5-32   2022-05-09 [1] CRAN (R 4.2.1)
 RgoogleMaps         1.4.5.3  2020-02-12 [1] CRAN (R 4.2.1)
 rjson               0.2.21   2022-01-09 [1] CRAN (R 4.2.0)
 rlang               1.0.5    2022-08-31 [1] CRAN (R 4.2.1)
 rmarkdown           2.14     2022-04-25 [1] CRAN (R 4.2.1)
 robustbase        * 0.95-0   2022-04-02 [1] CRAN (R 4.2.1)
 rstatix             0.7.0    2021-02-13 [1] CRAN (R 4.2.1)
 rstudioapi          0.13     2020-11-12 [1] CRAN (R 4.2.1)
 Rtsne               0.16     2022-04-17 [1] CRAN (R 4.2.1)
 rvest               1.0.2    2021-10-16 [1] CRAN (R 4.2.1)
 s2                  1.1.0    2022-07-18 [1] CRAN (R 4.2.1)
 scales              1.2.0    2022-04-13 [1] CRAN (R 4.2.1)
 sessioninfo         1.2.2    2021-12-06 [1] CRAN (R 4.2.1)
 sf                * 1.0-8    2022-07-14 [1] CRAN (R 4.2.1)
 sfheaders         * 0.4.0    2020-12-01 [1] CRAN (R 4.2.1)
 shiny               1.7.1    2021-10-02 [1] CRAN (R 4.2.1)
 simplevis         * 6.3.0    2022-06-07 [1] CRAN (R 4.2.1)
 sp                * 1.5-0    2022-06-05 [1] CRAN (R 4.2.1)
 spatialreg        * 1.2-3    2022-04-18 [1] CRAN (R 4.2.1)
 spData            * 2.0.1    2021-10-14 [1] CRAN (R 4.2.1)
 spdep               1.2-4    2022-04-18 [1] CRAN (R 4.2.1)
 splitstackshape   * 1.4.8    2019-04-21 [1] CRAN (R 4.2.1)
 stars             * 0.5-6    2022-07-21 [1] CRAN (R 4.2.1)
 stringi             1.7.8    2022-07-11 [1] CRAN (R 4.2.1)
 stringr           * 1.4.1    2022-08-20 [1] CRAN (R 4.2.1)
 terra             * 1.6-7    2022-08-07 [1] CRAN (R 4.2.1)
 tibble            * 3.1.7    2022-05-03 [1] CRAN (R 4.2.1)
 tidyr             * 1.2.0    2022-02-01 [1] CRAN (R 4.2.1)
 tidyselect          1.1.2    2022-02-21 [1] CRAN (R 4.2.1)
 tidyverse         * 1.3.2    2022-07-18 [1] CRAN (R 4.2.1)
 timeDate            3043.102 2018-02-21 [1] CRAN (R 4.2.0)
 tseries             0.10-51  2022-05-01 [1] CRAN (R 4.2.1)
 TTR                 0.24.3   2021-12-12 [1] CRAN (R 4.2.1)
 tzdb                0.3.0    2022-03-28 [1] CRAN (R 4.2.1)
 units               0.8-0    2022-02-05 [1] CRAN (R 4.2.1)
 urca                1.3-0    2016-09-06 [1] CRAN (R 4.2.1)
 urlchecker          1.0.1    2021-11-30 [1] CRAN (R 4.2.1)
 usethis           * 2.1.6    2022-05-25 [1] CRAN (R 4.2.1)
 utf8                1.2.2    2021-07-24 [1] CRAN (R 4.2.1)
 V8                  4.2.0    2022-05-14 [1] CRAN (R 4.2.1)
 vctrs               0.4.1    2022-04-13 [1] CRAN (R 4.2.1)
 viridisLite         0.4.0    2021-04-13 [1] CRAN (R 4.2.1)
 weathermetrics    * 1.2.2    2016-05-19 [1] CRAN (R 4.2.1)
 withr               2.5.0    2022-03-03 [1] CRAN (R 4.2.1)
 wk                  0.6.0    2022-01-03 [1] CRAN (R 4.2.1)
 xfun                0.32     2022-08-10 [1] CRAN (R 4.2.1)
 xml2                1.3.3    2021-11-30 [1] CRAN (R 4.2.1)
 xtable              1.8-4    2019-04-21 [1] CRAN (R 4.2.1)
 xts                 0.12.1   2020-09-09 [1] CRAN (R 4.2.1)
 yaml                2.3.5    2022-02-21 [1] CRAN (R 4.2.0)
 zoo                 1.8-10   2022-04-15 [1] CRAN (R 4.2.1)

Update:

As Ben pointed out spacetime is not in the sessioninfo list, so I tried loading the package spacetime version 1.2-8 and it fails to load after detaching all of the loaded packages with the same error:

Error: package or namespace load failed for ‘spacetime’:
 package slot missing from signature for generic ‘coerce’
and classes STFDF, RasterBrick
cannot use with duplicate class names (the package may need to be re-installed)
1

There are 1 best solutions below

0
On BEST ANSWER

tl;dr you probably need to restart R (not necessarily restarting RStudio; you can use Session > Restart R, which will restart your R session within RStudio).

?detach has a fairly involved description of what doesn't happen when you detach packages, and advises you to restart R if you need a clean environment. This is unfortunate, but it's the way it is.

If a package has a namespace, detaching it does not by default unload the namespace (and may not even with ‘unload = TRUE’), and detaching will not in general unload any dynamically loaded compiled code (DLLs); see ‘getLoadedDLLs’ and ‘library.dynam.unload’. Further, registered S3 methods from the namespace will not be removed, and because S3 methods are not tagged to their source on registration, it is in general not possible to safely un-register the methods associated with a given package. If you use ‘library’ on a package whose namespace is loaded, it attaches the exports of the already loaded namespace. So detaching and re-attaching a package may not refresh some or all components of the package, and is inadvisable. The most reliable way to completely detach a package is to restart R.

On a slightly broader note, if you have a clean workflow you generally should be able to start a new R session and get back to where you were without too much hassle:

  • if you some of your code takes a long time to re-run, you should probably be using targets or make (not an R package!) or some other workflow tool to avoid re-running upstream steps
  • if you can't rely on re-running your code to get you back to where you were, your workflow is inherently fragile/dangerous ...

This provides some useful advice on managing workflows in R.