Ironholds / rgeolocate

Generalised IP geolocation through R
https://cran.r-project.org/web/packages/rgeolocate/index.html
Other
66 stars 22 forks source link

Error using .mmdb files #43

Closed CodyLikavec closed 7 years ago

CodyLikavec commented 7 years ago

Hello,

I'm finding an error when I'm trying to use one of the external .mmdb files. I have downloaded the GeoLite2-City. mmdb file from http://dev.maxmind.com/geoip/geoip2/geolite2/ . I've also installed libmaxminddb via homebrew. My terminal now says Warning: libmaxminddb 1.2.1 is already installed when I try to reinstall it. So I BELIEVE I have everything I need to use the .mmdb file.

This code runs fine:

file <- system.file("extdata","GeoLite2-Country.mmdb", package = "rgeolocate")
results <- maxmind("196.200.60.51", file, "country_code")
print(results)

  country_code
1           ML

However, when I try this, I'm getting an error:

results <- maxmind("196.200.60.51", "./data/GeoLite2-City.mmdb", "country_code")

Error in maxmind_(ips, path.expand(file), fields) : 
  The geolocation database could not be opened

I know the GeoLite2-City.mmdb file is in the right place, as this runs fine:

> file.exists("./data/GeoLite2-City.mmdb")
[1] TRUE

I'm not sure what I may be doing wrong.

Ironholds commented 7 years ago

Well, it works for me:

> results <- maxmind("196.200.60.51", "../../../Downloads/GeoLite2-City_20170606/GeoLite2-City.mmdb", "country_code")
> 
> results
  country_code
1           ML

What's your R session information? For what it's worth you shouldn't need libmaxminddb at all - try seeing if removing it and then reinstalling the R package helps? (it shouldn't make a difference but hey)

CodyLikavec commented 7 years ago

I've uninstalled libmaxmindb. I've reinstalled the rgeolocate package. Still doesn't run, unfortunately.

> results <- maxmind("196.200.60.51", "./data/GeoLite2-City.mmdb", fields = c("latitude", "longitude"))
Error in maxmind_(ips, path.expand(file), fields) : 
  The geolocation database could not be opened
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] rjson_0.2.15       fields_9.0         maps_3.2.0         spam_1.4-0         rgeolocate_1.0.0   RMySQL_0.10.11     DBI_0.6-1         
 [8] dplyr_0.5.0        purrr_0.2.2.2      readr_1.1.1        tidyr_0.6.3        tibble_1.3.1       ggplot2_2.2.1.9000 tidyverse_1.1.1   
[15] RPostgres_0.1-4   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11     cellranger_1.1.0 compiler_3.4.0   plyr_1.8.4       forcats_0.2.0    tools_3.4.0      jsonlite_1.4     lubridate_1.6.0 
 [9] gtable_0.2.0     nlme_3.1-131     lattice_0.20-35  rlang_0.1.1      psych_1.7.5      parallel_3.4.0   haven_1.0.0      xml2_1.1.1      
[17] stringr_1.2.0    httr_1.2.1       knitr_1.16       hms_0.3          R6_2.2.1         readxl_1.0.0     foreign_0.8-67   reshape2_1.4.2  
[25] modelr_0.1.0     magrittr_1.5     scales_0.4.1     rvest_0.3.2      assertthat_0.2.0 mnormt_1.5-5     colorspace_1.3-2 stringi_1.1.5   
[33] lazyeval_0.2.0   munsell_0.4.3    broom_0.4.2
Ironholds commented 7 years ago

What does file.info for the mmdb file say?

Ironholds commented 7 years ago

And, do you get a different outcome if you use an absolute rather than relative path? (It shouldn't make a difference, but..)

Ironholds commented 7 years ago

And last but not least; what does path.expand("./data/Geo....") produce?

CodyLikavec commented 7 years ago

Wow. The absolute path worked and gives me results. It looks like something may be wrong with the relative path?

> path.expand("./data/GeoLite2-City.mmdb")
[1] "./data/GeoLite2-City.mmdb"

It looks like path.expand isn't actually showing the absolute path.

Ironholds commented 7 years ago

Aye, it looks like it shouldn't be! Let's see. Try installing via:

devtools::install_github("ironholds/rgeolocate")

And tell me if it works then (if so, I've fixed it - if not...I'm outta ideas)

CodyLikavec commented 7 years ago

It works! Using the "./data/GeoLite2-City.mmdb" file path instead of the full path gave me results.

Ironholds commented 7 years ago

That is, with the new version? And by that do you mean using the full path did not work?