Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geocode: add missing parameters to ldply call, closes #207 #210

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dpprdan
Copy link

@dpprdan dpprdan commented Mar 26, 2018

This ought to fix #207.

library(ggmap)
register_google(key = Sys.getenv("GOOGLE_GEOCODE_KEY"))

urlonly for multiple locations

places <- c("Houston, Texas", "Washington, DC")
geocode(places, urlonly = TRUE)
#>                                                                                                                         V1
#> 1 https://maps.googleapis.com/maps/api/geocode/json?address=Houston%2C%20Texas&key=my_google_key
#> 2 https://maps.googleapis.com/maps/api/geocode/json?address=Washington%2C%20DC&key=my_google_key

force for multiple locations

first call (so that results are cached)

geocode(places, force = FALSE)
#> Source : https://maps.googleapis.com/maps/api/geocode/json?address=Houston%2C%20Texas&key=my_google_key
#> Source : https://maps.googleapis.com/maps/api/geocode/json?address=Washington%2C%20DC&key=my_google_key
#>         lon      lat
#> 1 -95.36980 29.76043
#> 2 -77.03687 38.90719

second call

geocode(places, force = FALSE)
#>         lon      lat
#> 1 -95.36980 29.76043
#> 2 -77.03687 38.90719

Created on 2018-03-26 by the reprex package (v0.2.0).

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.4 (2018-03-15)
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language en                          
#>  collate  German_Germany.1252         
#>  tz       Europe/Berlin               
#>  date     2018-03-26
#> Packages -----------------------------------------------------------------
#>  package     * version    date       source                            
#>  assertthat    0.2.0      2017-04-11 CRAN (R 3.4.2)                    
#>  backports     1.1.2      2017-12-13 CRAN (R 3.4.3)                    
#>  base        * 3.4.4      2018-03-15 local                             
#>  bindr         0.1.1      2018-03-13 CRAN (R 3.4.4)                    
#>  bindrcpp    * 0.2        2017-06-17 CRAN (R 3.4.0)                    
#>  bitops        1.0-6      2013-08-17 CRAN (R 3.4.1)                    
#>  colorspace    1.3-2      2016-12-14 CRAN (R 3.4.2)                    
#>  compiler      3.4.4      2018-03-15 local                             
#>  datasets    * 3.4.4      2018-03-15 local                             
#>  devtools      1.13.5     2018-02-18 CRAN (R 3.4.3)                    
#>  digest        0.6.15     2018-01-28 CRAN (R 3.4.3)                    
#>  dplyr         0.7.4      2017-09-28 CRAN (R 3.4.2)                    
#>  evaluate      0.10.1     2017-06-24 CRAN (R 3.4.0)                    
#>  ggmap       * 2.7.900    2018-03-26 local                             
#>  ggplot2     * 2.2.1      2016-12-30 CRAN (R 3.4.3)                    
#>  glue          1.2.0.9000 2018-02-09 local                             
#>  graphics    * 3.4.4      2018-03-15 local                             
#>  grDevices   * 3.4.4      2018-03-15 local                             
#>  grid          3.4.4      2018-03-15 local                             
#>  gtable        0.2.0      2016-02-26 CRAN (R 3.4.2)                    
#>  htmltools     0.3.6      2017-04-28 CRAN (R 3.4.0)                    
#>  jpeg          0.1-8      2014-01-23 CRAN (R 3.4.1)                    
#>  knitr         1.20       2018-02-20 CRAN (R 3.4.3)                    
#>  lazyeval      0.2.1      2017-10-29 CRAN (R 3.4.2)                    
#>  magrittr      1.5        2014-11-22 CRAN (R 3.4.2)                    
#>  memoise       1.1.0      2018-01-08 Github (hadley/memoise@611cfad)   
#>  methods     * 3.4.4      2018-03-15 local                             
#>  munsell       0.4.3      2016-02-13 CRAN (R 3.4.2)                    
#>  pillar        1.2.1      2018-02-27 CRAN (R 3.4.3)                    
#>  pkgconfig     2.0.1      2017-03-21 CRAN (R 3.4.0)                    
#>  plyr          1.8.4      2016-06-08 CRAN (R 3.4.2)                    
#>  png           0.1-7      2013-12-03 CRAN (R 3.4.1)                    
#>  R6            2.2.2      2017-06-17 CRAN (R 3.4.0)                    
#>  Rcpp          0.12.16    2018-03-13 CRAN (R 3.4.4)                    
#>  RgoogleMaps   1.4.1      2016-09-18 CRAN (R 3.4.2)                    
#>  rjson         0.2.15     2014-11-03 CRAN (R 3.4.1)                    
#>  rlang         0.2.0.9000 2018-03-07 Github (tidyverse/rlang@d2ed2cf)  
#>  rmarkdown     1.9.2      2018-03-05 Github (rstudio/rmarkdown@9313596)
#>  rprojroot     1.3-2      2018-01-03 CRAN (R 3.4.3)                    
#>  scales        0.5.0.9000 2017-09-07 Github (hadley/scales@d767915)    
#>  stats       * 3.4.4      2018-03-15 local                             
#>  stringi       1.1.7      2018-03-12 CRAN (R 3.4.4)                    
#>  stringr       1.3.0      2018-02-19 CRAN (R 3.4.3)                    
#>  tibble        1.4.2      2018-01-22 CRAN (R 3.4.3)                    
#>  tools         3.4.4      2018-03-15 local                             
#>  utils       * 3.4.4      2018-03-15 local                             
#>  withr         2.1.2      2018-03-15 CRAN (R 3.4.4)                    
#>  yaml          2.1.18     2018-03-08 CRAN (R 3.4.4)
  • Did you run R CMD CHECK?
  • Did you run roxygen2::roxygenise(".")?

See #206 w.r.t. roxygenise

@scottmmjackson
Copy link
Collaborator

@dpprdan thanks for this. Do you want me to add unit tests (since this is drawn towards a bug)?

@dpprdan
Copy link
Author

dpprdan commented Apr 24, 2018

@scottmmjackson Sorry, I had not thought about this, but yeat, that would be great, because I won't have time for this the next couple of days!

@dpprdan
Copy link
Author

dpprdan commented Oct 26, 2018

I added tests. These are all based on urlonly = TRUE, otherwise one would need to call the API (which should probably better be mocked for testing via {httptest} or {webmockr}).

The tests for multiple locations depend on the result to be a (single-column) data.frame (due to ldply).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

geocode.R: urlonly parameter does not get passed to single-pass function call via ldply
2 participants