Closed darrennorris closed 1 year ago
This is the reason of your conflict: https://github.com/haozhu233/kableExtra/blob/master/R/landscape.R
Running this way after uploading all the packages works.
sample_lsm(landscapemetrics::landscape, y = sample_plots, what = "lsm_l_np")
thank you for such a quick and helpful reply.
Hi, I have run into an error that I think is to do with package conflicts but do not know how to solve. I am currently developing some analysis and starting to learn sample_lsm. I run the sample_lsm polygon example from the help with only landscapemetrics and it runs fine. I run using the packages I work with and get the folowing error. "Error in UseMethod("landscape_as_list") : no applicable method for 'landscape_as_list' applied to an object of class "function"" I am not sure what is causing this (appears to be a concflict with package kableExtra), any suggestions much appreciated. Example below. Best, Darren
library(landscapemetrics) poly_1 <- sp::Polygon(cbind(c(2.5, 2.5, 17.5, 17.5), c(-2.5, 12.5, 12.5, -2.5))) poly_2 <- sp::Polygon(cbind(c(7.5, 7.5, 23.5, 23.5), c(-7.5, 23.5, 23.5, -7.5))) poly_1 <- sp::Polygons(list(poly_1), "p1") poly_2 <- sp::Polygons(list(poly_2), "p2") sample_plots <- sp::SpatialPolygons(list(poly_1, poly_2)) sample_lsm(landscape, y = sample_plots, what = "lsm_l_np")
Above runs as expected. Below works fine with packages up to gridExtra. Error triggered when kableExtra is added in the following sequence.
library(tidyverse) library(sf) library(raster) library(terra) library(tmap) library(gridExtra) library(kableExtra)
poly_1 <- sp::Polygon(cbind(c(2.5, 2.5, 17.5, 17.5), c(-2.5, 12.5, 12.5, -2.5))) poly_2 <- sp::Polygon(cbind(c(7.5, 7.5, 23.5, 23.5), c(-7.5, 23.5, 23.5, -7.5))) poly_1 <- sp::Polygons(list(poly_1), "p1") poly_2 <- sp::Polygons(list(poly_2), "p2") sample_plots <- sp::SpatialPolygons(list(poly_1, poly_2)) sample_lsm(landscape, y = sample_plots, what = "lsm_l_np")
Error in UseMethod("landscape_as_list") : no applicable method for 'landscape_as_list' applied to an object of class "function"
Same error.
landscapemetrics::sample_lsm(landscape, y = sample_plots, what = "lsm_l_np") Error in UseMethod("landscape_as_list") : no applicable method for 'landscape_as_list' applied to an object of class "function"
utils::sessionInfo() R version 4.1.2 (2021-11-01) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] mgcv_1.8-42 nlme_3.1-162 mapview_2.11.0
[4] kableExtra_1.3.4 gridExtra_2.3 tmap_3.3-3
[7] terra_1.7-18 raster_3.6-20 sp_1.6-0
[10] sf_1.0-12 lubridate_1.9.2 forcats_1.0.0
[13] stringr_1.5.0 dplyr_1.1.1 purrr_1.0.1
[16] readr_2.1.4 tidyr_1.3.0 tibble_3.2.1
[19] ggplot2_3.4.2 tidyverse_2.0.0 landscapemetrics_1.5.6
loaded via a namespace (and not attached): [1] httr_1.4.5 splines_4.1.2 viridisLite_0.4.1 stats4_4.1.2
[5] pillar_1.9.0 lattice_0.20-45 glue_1.6.2 digest_0.6.31
[9] RColorBrewer_1.1-3 rvest_1.0.3 colorspace_2.1-0 Matrix_1.5-3
[13] htmltools_0.5.5 XML_3.99-0.14 pkgconfig_2.0.3 stars_0.6-1
[17] webshot_0.5.4 scales_1.2.1 svglite_2.1.1 satellite_1.0.4
[21] tzdb_0.3.0 timechange_0.2.0 proxy_0.4-27 generics_0.1.3
[25] withr_2.5.0 leafsync_0.1.0 cli_3.6.1 magrittr_2.0.3
[29] evaluate_0.20 fansi_1.0.4 xml2_1.3.3 lwgeom_0.2-11
[33] class_7.3-21 tools_4.1.2 hms_1.1.3 lifecycle_1.0.3
[37] munsell_0.5.0 compiler_4.1.2 e1071_1.7-13 systemfonts_1.0.4 [41] rlang_1.1.0 classInt_0.4-9 units_0.8-1 grid_4.1.2
[45] tmaptools_3.1-1 dichromat_2.0-0.1 rstudioapi_0.14 htmlwidgets_1.6.2 [49] crosstalk_1.2.0 leafem_0.2.0 base64enc_0.1-3 rmarkdown_2.21
[53] gtable_0.3.3 codetools_0.2-19 abind_1.4-5 DBI_1.1.3
[57] R6_2.5.1 knitr_1.42 fastmap_1.1.1 utf8_1.2.3
[61] KernSmooth_2.23-20 stringi_1.7.12 parallel_4.1.2 Rcpp_1.0.10
[65] vctrs_0.6.1 png_0.1-8 leaflet_2.1.2 tidyselect_1.2.0
[69] xfun_0.38