~hrbrmstr/uaparserjs

080f4245e7dce352e32701dc1f338463a4540f8a — hrbrmstr 4 years ago 0f21320
caching for minor speedup
4 files changed, 19 insertions(+), 3 deletions(-)

M DESCRIPTION
M NEWS.md
M R/uaparser.R
M R/zzz.r
M DESCRIPTION => DESCRIPTION +2 -2
@@ 1,8 1,8 @@
Package: uaparserjs
Type: Package
Title: Parse Browser 'User-Agent' Strings into Data Frames
Version: 0.1.0
Date: 2016-08-04
Version: 0.2.0.9000
Date: 2016-08-10
Authors@R: c(
    person("Bob", "Rudis", , "bob@rud.is", c("aut", "cre")),
    person("Lindsey", "Simon", role = "aut", comment = "uap-core"),

M NEWS.md => NEWS.md +3 -0
@@ 1,2 1,5 @@
0.2.0
* Caching for a minor speedup

0.1.0 
* Initial release

M R/uaparser.R => R/uaparser.R +10 -1
@@ 20,7 20,16 @@ ua_parse <- function(user_agents, .progress=FALSE) {
  if (.progress) pb <- progress_estimated(length(user_agents))
  purrr::map_df(user_agents, function(x) {
    if (.progress) pb$tick()$print()
    dplyr::as_data_frame(as.list(unlist(.pkgenv$ctx$call("parser.parse", x))))
    res <- .pkgenv$cache[[x]]
    if (length(res) > 0) {
      res
    } else {
      .pkgenv$cache[[x]] <- dplyr::as_data_frame(as.list(unlist(.pkgenv$ctx$call("parser.parse", x))))
      .pkgenv$cache[[x]]
    }
  })

}

#' @export
get_cache <- function() { .pkgenv$cache }
\ No newline at end of file

M R/zzz.r => R/zzz.r +4 -0
@@ 9,4 9,8 @@

  assign("ctx", ctx, envir=.pkgenv)

  cache <- list()

  assign("cache", cache, envir=.pkgenv)

}
\ No newline at end of file