Skip to content

Commit

Permalink
change read_geocode_cache() top load_geocode_cache()
Browse files Browse the repository at this point in the history
  • Loading branch information
dkahle committed Jun 17, 2020
1 parent a3cef89 commit 2a8c10a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export(inset)
export(inset_ggmap)
export(inset_raster)
export(legs2route)
export(load_geocode_cache)
export(make_bbox)
export(mapdist)
export(mutate_geocode)
export(qmap)
export(qmplot)
export(read_geocode_cache)
export(register_google)
export(retry_stamen_map_download)
export(revgeocode)
Expand Down
24 changes: 18 additions & 6 deletions R/geocode.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#' and appended to the query)
#' @param data a data frame or equivalent
#' @param path path to file
#' @param overwrite in [load_geocode_cache()], should the current cache be
#' wholly replaced with the one on file?
#' @param ... In [mutate_geocode()], arguments to pass to [geocode()]. In
#' [write_geocode_cache()], arguments to pass to [saveRDS()].
#' @return If \code{output} is "latlon", "latlona", or "more", a tibble (classed
Expand All @@ -27,8 +29,10 @@
#' @seealso \url{http://code.google.com/apis/maps/documentation/geocoding/},
#' \url{https://developers.google.com/maps/documentation/javascript/geocoding},
#'
#'
#' \url{https://developers.google.com/maps/documentation/geocoding/usage-limits}
#'
#'
#' @name geocode
#' @examples
#'
Expand Down Expand Up @@ -511,28 +515,36 @@ write_geocode_cache <- function (path, ...) {




#' @export
#' @rdname geocode
read_geocode_cache <- function(path) {
load_geocode_cache <- function(path, overwrite = FALSE) {

if (!exists(".geocode_cache", envir = ggmap_environment)) {

assign(".geocode_cache", list(), ggmap_environment)

} else {

assign(
".geocode_cache",
c(geocode_cache(), readRDS(path)),
ggmap_environment
)
if (overwrite) {
assign(".geocode_cache", readRDS(path), ggmap_environment)
} else {
assign(
".geocode_cache",
c(geocode_cache(), readRDS(path)),
ggmap_environment
)
}

}

}






#' @export
#' @rdname geocode
clear_geocode_cache <- function(path) {
Expand Down
7 changes: 5 additions & 2 deletions man/geocode.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2a8c10a

Please sign in to comment.