ropensci / CoordinateCleaner

Automated flagging of common spatial and temporal errors in biological and palaeontological collection data, for the use in conservation, ecology and palaeontology.
https://docs.ropensci.org/CoordinateCleaner/
79 stars 21 forks source link

cc_coun not working on new version of rnaturalearthdata #29

Closed jivelasquezt closed 4 years ago

jivelasquezt commented 5 years ago

The version 0.1.0 of rnaturalearthdata does not have a "iso_a3_eh" field in the ne_countries object. This causes cc_coun to crash whenever is used, by returning the following error

Error in [.data.frame(sp::over(x = dat, y = ref), , "iso_a3_eh") : undefined columns selected

traceback()

5: stop("undefined columns selected") 4: [.data.frame(sp::over(x = dat, y = ref), , "iso_a3_eh") 3: sp::over(x = dat, y = ref)[, "iso_a3_eh"] 2: cc_coun(x, lon = lon, lat = lat, iso3 = countries, ref = country_ref, verbose = verbose, value = "flagged") 1: CoordinateCleaner::clean_coordinates(occ.table.clean, lon = "decimalLongitude", lat = "decimalLatitude", species = "species", countries = "countryCode", value = "clean", tests = c("countries", "capitals", "centroids", "equal", "gbif", "institutions", "outliers", "seas", "zeros"))

Reproducible example CoordinateCleaner version 2.0-11 rnaturalearth version 0.1.0 rnaturalearthdata version 0.1.0

#occ.table is a data frame downloaded from gbif in simple_csv format
library(ISOcodes)
occ.table$countryCode <- ISO_3166_1$Alpha_3[match(occ.table$countryCode, ISOcodes::ISO_3166_1$Alpha_2)] #Change ISO2 for ISO3 as required by CoordinateCleaner
occ.table.clean <- CoordinateCleaner::clean_coordinates(occ.table.clean,
                                                        lon="decimalLongitude",
                                                        lat="decimalLatitude",
                                                        species="species",
                                                        countries = "countryCode",
                                                        value="clean",
                                                        tests=c("countries","capitals","centroids", "equal", "gbif",
                                                                "institutions", "outliers", "seas","zeros"))
tretherington commented 4 years ago

@jivelasquezt thanks for explaining the issue and presenting a fix for both the rnaturalearthdata and for GBIF data having 2 letter country codes 👍😃

azizka commented 4 years ago

See here for fix: #25