代码之家  ›  专栏  ›  技术社区  ›  user41509

无法理解关于spatialEco包的命名空间R的错误消息

  •  0
  • user41509  · 技术社区  · 7 月前

    多年来,我一直在spatialEco包中使用相同的代码和函数point.in.poly。今天我收到一条错误消息: “错误:'point.in.poly'不是从'namespace:spaceEco'导出的对象”。

    我试着研究错误信息,但又在绕圈子。我希望有人能向我解释错误消息。这是我第一次遇到此消息。

    以下是我的R会话信息:

    sessionInfo()
    R version 4.4.1 (2024-06-14 ucrt)
    Platform: x86_64-w64-mingw32/x64
    Running under: Windows 11 x64 (build 26100)
    
    Matrix products: default
    
    
    locale:
    [1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
    [4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    
    
    time zone: America/New_York
    tzcode source: internal
    
    attached base packages:
    [1] splines   stats4    stats     graphics  grDevices utils     datasets  methods   base     
    
    other attached packages:
     [1] ggpubr_0.6.0     snow_0.4-4       bbmle_1.0.25.1   selfisher_1.1.0  stringr_1.5.1    tidyr_1.3.1      car_3.1-3        carData_3.0-5   
     [9] ez_4.4-0         reshape2_1.4.4   scales_1.3.0     ggmap_4.0.0      ggplot2_3.5.1    ggnewscale_0.5.0 spatialEco_2.0-2 shapefiles_0.7.2
    [17] foreign_0.8-86   classInt_0.4-10  mapplots_1.5.2   rgdal_1.6-7      GISTools_1.0-2   sf_1.0-19        maptools_1.1-8   sp_2.1-4        
    [25] mapdata_2.3.1    maps_3.4.2.1     lattice_0.22-6   plyr_1.8.9       dplyr_1.1.4      DBI_1.2.3        odbc_1.5.0      
    
    loaded via a namespace (and not attached):
     [1] tidyselect_1.2.1    blob_1.2.4          bitops_1.0-9        lifecycle_1.0.4     terra_1.7-83        magrittr_2.0.3     
     [7] compiler_4.4.1      rlang_1.1.4         tools_4.4.1         utf8_1.2.4          ggsignif_0.6.4      bit_4.5.0          
    [13] RColorBrewer_1.1-3  abind_1.4-8         KernSmooth_2.23-24  withr_3.0.2         purrr_1.0.2         numDeriv_2016.8-1.1
    [19] grid_4.4.1          fansi_1.0.6         e1071_1.7-16        colorspace_2.1-1    MASS_7.3-60.2       mvtnorm_1.3-2      
    [25] cli_3.6.3           reformulas_0.4.0    generics_0.1.3      rstudioapi_0.17.1   httr_1.4.7          bdsmatrix_1.3-7    
    [31] minqa_1.2.8         proxy_0.4-27        parallel_4.4.1      vctrs_0.6.5         boot_1.3-30         Matrix_1.7-0       
    [37] hms_1.1.3           rstatix_0.7.2       bit64_4.5.2         Formula_1.2-5       jpeg_0.1-10         units_0.8-5        
    [43] glue_1.8.0          nloptr_2.1.1        codetools_0.2-20    stringi_1.8.4       gtable_0.3.6        lme4_1.1-36        
    [49] munsell_0.5.1       tibble_3.2.1        pillar_1.9.0        R6_2.5.1            TMB_1.9.16          Rdpack_2.6.2       
    [55] backports_1.5.0     rbibutils_2.3       png_0.1-8           broom_1.0.7         class_7.3-22        Rcpp_1.0.14        
    [61] nlme_3.1-164        mgcv_1.9-1          pkgconfig_2.0.3    
    
    1 回复  |  直到 7 月前
        1
  •  3
  •   Ben Bolker    7 月前

    正如前文所述 here , point.in.poly 已被弃用,取而代之的是 sf::st_intersection 并且在版本2.0-2中被删除。因此,您无法使用该函数,因为它没有定义。对此有两种解决方案:

    1. 代替 point.in.poly() 通过 sf::st_intersection() .

    2. 定义 点in.poly 你自己。代码为 点in.poly 是:

    point.in.poly <- function(dt, poly_shape) {
      dt_pp <- dt[!is.na(sp::over(dt, sp::geometry(poly_shape))), ]
      dt_pp@data <- data.frame(dt_pp@data, sp::over(dt_pp, poly_shape))
      dt_pp@proj4string <- dt@proj4string
      dt_pp
    }
    
    推荐文章