Seeking Expert Opinion on R Error with `sf` Package

Hello everyone,

I'm working on a project that involves extracting points of interest (POI) data using a custom function. I have encountered an error related to the sf package in R and would appreciate any guidance or insights from the community.

Code Snippet

Here is the relevant part of my code:

# Implement Functions ----------------------------------------------------------
#### N POI
for(buffer_i in BUFFER_OSM){
  for(country_code_i in country_codes_all){
    print(paste0("N POI: ", country_code_i, " - ", buffer_i, " =============="))
   
    OUT_PATH <- file.path(data_dir, SURVEY_NAME,
                          "FinalData", "Individual Datasets", "osm", "poi",
                          paste0("osm_",country_code_i,"_n_poi_",buffer_i,"m_buff.Rds"))
   
    if(!file.exists(OUT_PATH) | REPLACE_IF_EXTRACTED){
      survey_df_i <- extract_n_poi(buffer_i, country_code_i, survey_df, osm_dir_df)
      saveRDS(survey_df_i, OUT_PATH)
    }
  }
}

Error Message

I am encountering the following error:

Error in h(simpleError(msg, call)) :
  error in evaluating the argument 'x' in selecting a method for function 'as.data.frame': unable to find an inherited method for function ‘coordinates’ for signature ‘"sf"’

Context

  • Function extract_n_poi: This function is supposed to extract POI data based on a given buffer and country code.
  • Data: I am using the sf package for spatial data manipulation.

Request for Help

Has anyone faced a similar issue with the sf package or coordinates function? I suspect the problem might be related to the compatibility between the sf objects and the coordinates function, but I'm not sure how to resolve it.

Any advice on how to debug this error or suggestions for alternative approaches would be greatly appreciated.

Thank you for your help!

Hi @GIS243 ,

As a first step in helping folks here understand what might be going on, could you run your code and post a screenshot of the full output associated with the error?