brunobrr / bdc

Check out the vignettes with detailed documentation on each module of the bdc package
https://brunobrr.github.io/bdc
GNU General Public License v3.0
23 stars 7 forks source link

bdc_country_from_coordinates() identifies correct countries but assigns them to incorrect rows #209

Closed max-sfeeri closed 2 years ago

max-sfeeri commented 2 years ago

I am using bdc_country_from_coordinates() to find the appropriate countries for a long list of coordinates that do not have country information assigned to they. I found that the method does find the correct country for each coordinate, but in the process of outputting them, assigns the wrong country to the points.

Example that reproduces issue:

point1 = Finland, point2 = Sweden, point3 = Norway, point4 = Estonia)

decimalLatitude = c(62.587273591263624, 66.62443625769812, 60.91266175537055, 59.166132649248496) decimalLongitude = c(30.81351622904529, 21.219645421093123, 10.65224213789756, 25.883878594365648) country = c("","","","") testframe <- data.frame(decimalLatitude, decimalLongitude, country)

bdc_country_from_coordinates(testframe)

bdc_country_from_coordinates: Country names were added to 4 records.

decimalLatitude decimalLongitude country 1 62.58727 30.81352 Estonia 2 66.62444 21.21965 Norway 3 60.91266 10.65224 Sweden 4 59.16613 25.88388 Finland

The output order is: Estonia, Norway, Sweden & Finland. The correct output order for these points should be Finland, Sweden, Norway & Estonia.

kguidonimartins commented 2 years ago

Thanks for reporting! Can you test again using the development version of {bdc}, please? We’ll push a new version to CRAN in a few weeks.

if (!require("remotes")) install.packages("remotes")
#> Loading required package: remotes
## install the development version
remotes::install_github("brunobrr/bdc", force = TRUE)
#> Downloading GitHub repo brunobrr/bdc@HEAD
#> 
#> * checking for file ‘/tmp/RtmpJcjy26/remotes2624128d4591/brunobrr-bdc-ff3f265/DESCRIPTION’ ... OK
#> * preparing ‘bdc’:
#> * checking DESCRIPTION meta-information ... OK
#> * checking for LF line-endings in source and make files and shell scripts
#> * checking for empty or unneeded directories
#> * building ‘bdc_1.0.0.tar.gz’
#> Installing package into '/home/karlo/.local/lib/R/library/4.1'
#> (as 'lib' is unspecified)
library(bdc)

decimalLatitude <- c(62.587273591263624, 66.62443625769812, 60.91266175537055, 59.166132649248496)
decimalLongitude <- c(30.81351622904529, 21.219645421093123, 10.65224213789756, 25.883878594365648)
country <- c("", "", "", "")
testframe <- data.frame(decimalLatitude, decimalLongitude, country)

bdc_country_from_coordinates(testframe)
#> Loading required package: rnaturalearth
#> Loading required package: rnaturalearthdata
#> 
#> bdc_country_from_coordinates:
#> Country names were added to 4 records.
#>   decimalLatitude decimalLongitude country
#> 1        62.58727         30.81352 Finland
#> 2        66.62444         21.21965  Sweden
#> 3        60.91266         10.65224  Norway
#> 4        59.16613         25.88388 Estonia

Created on 2022-03-09 by the reprex package (v2.0.1)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.2 (2021-11-01) #> os Arch Linux #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype pt_BR.UTF-8 #> tz America/Sao_Paulo #> date 2022-03-09 #> pandoc 2.14.2 @ /usr/lib/rstudio/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> arkdb 0.0.15 2022-02-15 [1] CRAN (R 4.1.2) #> askpass 1.1 2019-01-13 [1] CRAN (R 4.1.1) #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.1) #> backports 1.4.1 2021-12-13 [1] CRAN (R 4.1.2) #> bdc * 1.0.0 2022-03-09 [1] Github (brunobrr/bdc@ff3f265) #> callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.1) #> class 7.3-19 2021-05-03 [2] CRAN (R 4.1.2) #> classInt 0.4-3 2020-04-07 [1] CRAN (R 4.1.1) #> cli 3.2.0 2022-02-14 [1] CRAN (R 4.1.2) #> codetools 0.2-18 2020-11-04 [2] CRAN (R 4.1.2) #> colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.1.2) #> conditionz 0.1.0 2019-04-24 [1] CRAN (R 4.1.1) #> contentid 0.0.15 2021-11-29 [1] CRAN (R 4.1.2) #> CoordinateCleaner 2.0-20 2021-10-21 [1] CRAN (R 4.1.2) #> crayon 1.5.0 2022-02-14 [1] CRAN (R 4.1.2) #> curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.1) #> data.table 1.14.2 2021-09-27 [1] CRAN (R 4.1.1) #> DBI 1.1.2 2021-12-20 [1] CRAN (R 4.1.2) #> dbplyr 2.1.1 2021-04-06 [1] CRAN (R 4.1.1) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.2) #> dplyr 1.0.8 2022-02-08 [1] CRAN (R 4.1.2) #> DT 0.21 2022-02-26 [1] CRAN (R 4.1.2) #> e1071 1.7-9 2021-09-16 [1] CRAN (R 4.1.1) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.1) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.1) #> fansi 1.0.2 2022-01-14 [1] CRAN (R 4.1.2) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.1) #> foreach 1.5.2 2022-02-02 [1] CRAN (R 4.1.2) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.2) #> generics 0.1.2 2022-01-31 [1] CRAN (R 4.1.2) #> geosphere 1.5-14 2021-10-13 [1] CRAN (R 4.1.2) #> ggplot2 3.3.5 2021-06-25 [1] CRAN (R 4.1.1) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.1.2) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.1) #> here 1.0.1 2020-12-13 [1] CRAN (R 4.1.1) #> highr 0.9 2021-04-16 [1] CRAN (R 4.1.1) #> hms 1.1.1 2021-09-26 [1] CRAN (R 4.1.1) #> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1) #> htmlwidgets 1.5.4 2021-09-08 [1] CRAN (R 4.1.1) #> httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.1) #> iterators 1.0.14 2022-02-05 [1] CRAN (R 4.1.2) #> jsonlite 1.8.0 2022-02-22 [1] CRAN (R 4.1.2) #> KernSmooth 2.23-20 2021-05-03 [2] CRAN (R 4.1.2) #> knitr 1.37 2021-12-16 [1] CRAN (R 4.1.2) #> lattice 0.20-45 2021-09-22 [2] CRAN (R 4.1.2) #> lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.1.1) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.1) #> magrittr 2.0.2 2022-01-26 [1] CRAN (R 4.1.2) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.1) #> oai 0.3.2 2021-05-13 [1] CRAN (R 4.1.1) #> openssl 2.0.0 2022-03-02 [1] CRAN (R 4.1.2) #> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.1.2) #> pkgbuild 1.3.1 2021-12-20 [1] CRAN (R 4.1.2) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.1) #> plyr 1.8.6 2020-03-03 [1] CRAN (R 4.1.1) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.1) #> processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.1) #> progress 1.2.2 2019-05-16 [1] CRAN (R 4.1.1) #> proxy 0.4-26 2021-06-07 [1] CRAN (R 4.1.1) #> ps 1.6.0 2021-02-28 [1] CRAN (R 4.1.1) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.1) #> qs 0.25.3 2022-02-22 [1] CRAN (R 4.1.2) #> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.1.1) #> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.1.1) #> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.1.1) #> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.1.1) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.1) #> RApiSerialize 0.1.0 2014-04-19 [1] CRAN (R 4.1.1) #> raster 3.5-15 2022-01-22 [1] CRAN (R 4.1.2) #> Rcpp 1.0.8 2022-01-13 [1] CRAN (R 4.1.2) #> RcppParallel 5.1.5 2022-01-05 [1] CRAN (R 4.1.2) #> readr 2.1.2 2022-01-30 [1] CRAN (R 4.1.2) #> remotes * 2.4.2 2021-11-30 [1] CRAN (R 4.1.2) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.1) #> rgbif 3.7.0 2022-02-08 [1] CRAN (R 4.1.2) #> rgdal 1.5-28 2021-12-15 [1] CRAN (R 4.1.2) #> rgeos 0.5-9 2021-12-15 [1] CRAN (R 4.1.2) #> rgnparser 0.2.0 2021-01-25 [1] CRAN (R 4.1.1) #> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.1.2) #> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.1) #> rnaturalearth * 0.1.0 2017-03-21 [1] CRAN (R 4.1.1) #> rnaturalearthdata * 0.1.0 2017-02-21 [1] CRAN (R 4.1.2) #> rnaturalearthhires 0.2.0 2022-02-19 [1] Github (ropensci/rnaturalearthhires@2ed7a93) #> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.1) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.1) #> s2 1.0.7 2021-09-28 [1] CRAN (R 4.1.1) #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.1.1) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.2) #> sf 1.0-7 2022-03-07 [1] CRAN (R 4.1.2) #> sp 1.4-6 2021-11-14 [1] CRAN (R 4.1.2) #> stringfish 0.15.5 2021-12-01 [1] CRAN (R 4.1.2) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.2) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.1) #> styler 1.6.2 2021-09-23 [1] CRAN (R 4.1.1) #> sys 3.4 2020-07-23 [1] CRAN (R 4.1.1) #> taxadb 0.1.4 2022-03-05 [1] CRAN (R 4.1.2) #> terra 1.5-21 2022-02-17 [1] CRAN (R 4.1.2) #> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.1.2) #> tidyselect 1.1.2 2022-02-21 [1] CRAN (R 4.1.2) #> tzdb 0.2.0 2021-10-27 [1] CRAN (R 4.1.2) #> units 0.8-0 2022-02-05 [1] CRAN (R 4.1.2) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.1) #> uuid 1.0-3 2021-11-01 [1] CRAN (R 4.1.2) #> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.1) #> wellknown 0.7.4 2021-05-25 [1] CRAN (R 4.1.1) #> whisker 0.4 2019-08-28 [1] CRAN (R 4.1.1) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.1.2) #> wk 0.6.0 2022-01-03 [1] CRAN (R 4.1.2) #> xfun 0.29 2021-12-14 [1] CRAN (R 4.1.2) #> xml2 1.3.3 2021-11-30 [1] CRAN (R 4.1.2) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.1.2) #> #> [1] /home/karlo/.local/lib/R/library/4.1 #> [2] /usr/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
max-sfeeri commented 2 years ago

Thanks for the quick reply! I'll try this out tomorrow and report back.

max-sfeeri commented 2 years ago

Update: seems to be working! Tried it out with a few different configurations of coordinates, and now it returns the correct countries in the correct order.

kguidonimartins commented 2 years ago

Great! I'm closing this issue for now. Feel free to reopen if needed.