rspatial

Do not understand error message about namespace R with spatialEco package


I have been using the same code and function point.in.poly in the spatialEco package for several years. Today I am getting an error message: "Error: 'point.in.poly' is not an exported object from 'namespace:spatialEco'".

I have tried researching the error message but am going around in circles. I was hoping someone could explain the error message to me. This is the first time I have encountered this message.

Here is my R session information:

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    

Solution

  • As mentioned in here, point.in.poly is deprecated in favor of sf::st_intersection and is removed in version 2.0-2. Therefore, you cannot use the function as it is not defined. There are two solutions for this:

    1. Replace point.in.poly() by sf::st_intersection().

    2. Define point.in.poly yourself. The code for point.in.poly is:

    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
    }