munterfi / hereR

R package that provides an interface to the HERE REST APIs: Geocoder API, Routing API, Traffic API, Public Transit API and Destination Weather API. Locations and routes are returned as 'sf' objects.
https://munterfi.github.io/hereR/
GNU General Public License v3.0
89 stars 11 forks source link

rate-limit-related functions to freemium (1) #138

Closed szaboildi closed 3 years ago

szaboildi commented 3 years ago

Rename the rate-limit-related variable HERE_RPS to HERE_FREEMIUM, and the functions hereR::set_rate_limit() and .get_freemium() functions to hereR::set_freemium() and .get_freemium(), respectively. Change the documentation to reflect the additional purpose of the now hereR::set_freemium() function. Use the HERE_FREEMIUM variable to determine a plan-specific size of sub-matrices in the hereR::route_matrix() function.

munterfi commented 3 years ago

Hi, thanks for your contribution!

I reopened the PR and:

Concerning the error message if freemium is deactivated and a large matrix is sent, it will return NULL and issue the warning “403 Forbidden”, which is OK I think:

library(hereR)
set_verbose(TRUE)
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
n <- 200
l <- n * n
(sf <-
  data.frame(
    idx = seq(1, n),
    lng = runif(n, 7.5, 8.5),
    lat = runif(n, 47.25, 47.75)
  ) %>%
  st_as_sf(coords = c("lng", "lat")) %>%
  st_set_crs(4326))
#> Simple feature collection with 200 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 7.501837 ymin: 47.25312 xmax: 8.497909 ymax: 47.74764
#> Geodetic CRS:  WGS 84
#> First 10 features:
#>    idx                  geometry
#> 1    1 POINT (7.651816 47.54143)
#> 2    2 POINT (8.008282 47.40666)
#> 3    3 POINT (8.434565 47.66038)
#> 4    4  POINT (8.02256 47.56635)
#> 5    5 POINT (7.504335 47.65751)
#> 6    6 POINT (7.960898 47.35633)
#> 7    7  POINT (7.622075 47.3893)
#> 8    8 POINT (8.345096 47.55927)
#> 9    9  POINT (7.709078 47.6904)
#> 10  10 POINT (8.424419 47.62594)
m1 <- route_matrix(sf)
#> Sending 28 request(s) with 1 RPS to: 'https://matrix.router.hereapi.com/v8/matrix?...'
#> Received 28 response(s) with total size: 436.7 Kb
set_freemium(FALSE)
(m2 <- route_matrix(sf))
#> Sending 1 request(s) with unlimited RPS to: 'https://matrix.router.hereapi.com/v8/matrix?...'
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 1' failed:
#> Status 403.
#> Received 1 response(s) with total size: 288 bytes
#> NULL
Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.0 (2021-05-18) #> os macOS Big Sur 10.16 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Europe/Zurich #> date 2021-09-22 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> cachem 1.0.6 2021-08-19 [1] CRAN (R 4.1.0) #> callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.0) #> class 7.3-19 2021-05-03 [1] CRAN (R 4.1.0) #> classInt 0.4-3 2020-04-07 [1] CRAN (R 4.1.0) #> cli 3.0.1 2021-07-17 [1] CRAN (R 4.1.0) #> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.1.0) #> crul 1.1.0 2021-02-15 [1] CRAN (R 4.1.0) #> curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.0) #> data.table 1.14.0 2021-02-21 [1] CRAN (R 4.1.0) #> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.0) #> desc 1.3.0 2021-03-05 [1] CRAN (R 4.1.0) #> devtools 2.4.2 2021-06-07 [1] CRAN (R 4.1.0) #> digest 0.6.27 2020-10-24 [1] CRAN (R 4.1.0) #> dplyr 1.0.7 2021-06-18 [1] CRAN (R 4.1.0) #> e1071 1.7-8 2021-07-28 [1] CRAN (R 4.1.0) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.0) #> fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.0) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0) #> fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.0) #> generics 0.1.0 2020-10-31 [1] CRAN (R 4.1.0) #> glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.0) #> hereR * 0.7.1.9000 2021-09-22 [1] local #> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.0) #> httpcode 0.3.0 2020-04-10 [1] CRAN (R 4.1.0) #> jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.1.0) #> KernSmooth 2.23-20 2021-05-03 [1] CRAN (R 4.1.0) #> knitr 1.34 2021-09-09 [1] CRAN (R 4.1.0) #> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.1.0) #> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0) #> memoise 2.0.0 2021-01-26 [1] CRAN (R 4.1.0) #> pillar 1.6.2 2021-07-29 [1] CRAN (R 4.1.0) #> pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.1.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0) #> pkgload 1.2.2 2021-09-11 [1] CRAN (R 4.1.0) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0) #> processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.0) #> proxy 0.4-26 2021-06-07 [1] CRAN (R 4.1.0) #> ps 1.6.0 2021-02-28 [1] CRAN (R 4.1.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0) #> Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.1.0) #> remotes 2.4.0 2021-06-02 [1] CRAN (R 4.1.0) #> rlang 0.4.11 2021-04-30 [1] CRAN (R 4.1.0) #> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.0) #> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.0) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.1.0) #> sf * 1.0-2 2021-07-26 [1] CRAN (R 4.1.0) #> stringi 1.7.4 2021-08-25 [1] CRAN (R 4.1.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0) #> testthat 3.0.4 2021-07-01 [1] CRAN (R 4.1.0) #> tibble 3.1.4 2021-08-25 [1] CRAN (R 4.1.0) #> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0) #> units 0.7-2 2021-06-08 [1] CRAN (R 4.1.0) #> usethis 2.0.1 2021-02-10 [1] CRAN (R 4.1.0) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0) #> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0) #> withr 2.4.2 2021-04-18 [1] CRAN (R 4.1.0) #> xfun 0.26 2021-09-14 [1] CRAN (R 4.1.0) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library ```

szaboildi commented 3 years ago

Sounds good, thank you!