running ` devtools::install_github('dkahle/ggmap')` causing `Error in `*tmp*`[[c(1, 1)]] : subscript out of bounds`
Hey,
I ran devtools::install_github('dkahle/ggmap') when trying to fix the issue of ggmap mapdist function repeating calculation for certain O-D pairs.
before running this the code mapdist('Manchester Deaf Institute', 'Birmingham O2 Academy 1', mode = 'driving') would return a result, however now after running devtools::install_github('dkahle/ggmap')
I just get the following error Error in tmp[[c(1, 1)]] : subscript out of bounds
I am no where near the API limit for the day, and as this was working perfectly beforehand I am unsure why this is not working ( I am not sure it this is similar to this issue https://github.com/dkahle/ggmap/issues/166)
Is this a known issue?
thanks
I can't reproduce this with the latest version of ggmap. Would you mind running a reprex with the system information flag set, like this?
reprex::reprex({
library(ggmap)
mapdist('Manchester Deaf Institute', 'Birmingham O2 Academy 1', mode = 'driving')
}, si = T)
My Output
library(ggmap)
#> Loading required package: ggplot2
#> Google Maps API Terms of Service: http://developers.google.com/maps/terms.
#> Please cite ggmap if you use it: see citation("ggmap") for details.
mapdist("Manchester Deaf Institute", "Birmingham O2 Academy 1", mode = "driving")
#> Source : https://maps.googleapis.com/maps/api/distancematrix/json?origins=Manchester%20Deaf%20Institute&destinations=Birmingham%20O2%20Academy%201&mode=driving&language=en-EN
#> from to m km miles
#> 1 Manchester Deaf Institute Birmingham O2 Academy 1 141330 141.33 87.82246
#> seconds minutes hours
#> 1 6576 109.6 1.826667
Session info
devtools::session_info()
#> Warning in as.POSIXlt.POSIXct(Sys.time()): unknown timezone 'zone/tz/2018c.
#> 1.0/zoneinfo/America/New_York'
#> ─ Session info ──────────────────────────────────────────────────────────
#> setting value
#> version R version 3.3.3 (2017-03-06)
#> os macOS 10.13.4
#> system x86_64, darwin13.4.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> tz <NA>
#> date 2018-05-07
#>
#> ─ Packages ──────────────────────────────────────────────────────────────
#> package * version date source
#> assertthat 0.2.0 2017-04-11 cran (@0.2.0)
#> backports 1.1.2 2017-12-13 cran (@1.1.2)
#> bindr 0.1 2016-11-13 cran (@0.1)
#> bindrcpp 0.2 2017-06-17 CRAN (R 3.3.2)
#> bitops 1.0-6 2013-08-17 CRAN (R 3.3.0)
#> callr 2.0.1 2018-01-30 CRAN (R 3.3.3)
#> cli 1.0.0 2017-11-05 cran (@1.0.0)
#> clisymbols 1.2.0 2017-05-21 cran (@1.2.0)
#> colorspace 1.3-2 2016-12-14 CRAN (R 3.3.2)
#> crayon 1.3.4 2018-04-30 Github (r-lib/crayon@95b3eae)
#> debugme 1.1.0 2017-10-22 CRAN (R 3.3.2)
#> desc 1.1.1 2017-08-03 CRAN (R 3.3.2)
#> devtools 1.13.5.9000 2018-02-22 Github (hadley/devtools@c890eaf)
#> digest 0.6.13 2017-12-14 cran (@0.6.13)
#> dplyr 0.7.4 2017-09-28 cran (@0.7.4)
#> evaluate 0.10.1 2017-06-24 cran (@0.10.1)
#> formatR 1.5 2017-04-25 CRAN (R 3.3.2)
#> ggmap * 2.7.900 2018-04-30 local
#> ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.3.2)
#> glue 1.2.0 2017-10-29 cran (@1.2.0)
#> gtable 0.2.0 2016-02-26 CRAN (R 3.3.0)
#> htmltools 0.3.6 2017-04-28 cran (@0.3.6)
#> jpeg 0.1-8 2014-01-23 CRAN (R 3.3.0)
#> knitr 1.20 2018-03-30 Github (yihui/knitr@03b6e40)
#> lazyeval 0.2.1 2017-10-29 CRAN (R 3.3.2)
#> magrittr 1.5 2014-11-22 CRAN (R 3.3.0)
#> memoise 1.1.0 2017-04-21 CRAN (R 3.3.2)
#> munsell 0.4.3 2016-02-13 CRAN (R 3.3.0)
#> pillar 1.2.2 2018-04-30 Github (hadley/colformat@534f7e8)
#> pkgbuild 0.0.0.9000 2018-02-22 Github (r-lib/pkgbuild@4a85872)
#> pkgconfig 2.0.1 2017-03-21 cran (@2.0.1)
#> pkgload 0.0.0.9000 2018-02-22 Github (r-lib/pkgload@884e79d)
#> plyr 1.8.4 2016-06-08 CRAN (R 3.3.0)
#> png 0.1-7 2013-12-03 CRAN (R 3.3.0)
#> R6 2.2.2 2017-06-17 cran (@2.2.2)
#> Rcpp 0.12.14 2017-11-23 cran (@0.12.14)
#> RgoogleMaps 1.4.1 2016-09-18 CRAN (R 3.3.0)
#> rjson 0.2.15 2014-11-03 CRAN (R 3.3.0)
#> rlang 0.2.0.9001 2018-04-30 Github (tidyverse/rlang@82b2727)
#> rmarkdown 1.9.8 2018-03-30 Github (rstudio/rmarkdown@8cfc878)
#> rprojroot 1.3-2 2018-01-03 cran (@1.3-2)
#> scales 0.5.0.9000 2018-04-30 Github (hadley/scales@d767915)
#> sessioninfo 1.0.0 2017-06-21 cran (@1.0.0)
#> stringi 1.1.6 2017-11-17 cran (@1.1.6)
#> stringr 1.3.0 2018-02-19 cran (@1.3.0)
#> testthat 2.0.0 2017-12-13 cran (@2.0.0)
#> tibble 1.4.2.9001 2018-04-30 Github (hadley/tibble@b90a4fd)
#> usethis 1.1.0 2017-11-17 cran (@1.1.0)
#> withr 2.1.2 2018-04-30 Github (jimhester/withr@79d7b0d)
#> yaml 2.1.16 2017-12-12 cran (@2.1.16)
The problem might be in the rjson package. See the example below for a comparison between rjson and jsonlite. I did not test with earlier versions of rjson.
library(ggmap)
#> Loading required package: ggplot2
#> Google Maps API Terms of Service: http://developers.google.com/maps/terms.
#> Please cite ggmap if you use it: see citation("ggmap") for details.
mapdist("Manchester Deaf Institute", "Birmingham O2 Academy 1", mode = "driving")
#> unsupported SEXPTYPE: 19
#> Source : https://maps.googleapis.com/maps/api/distancematrix/json?origins=Manchester%20Deaf%20Institute&destinations=Birmingham%20O2%20Academy%201&mode=driving&language=en-EN
#> Error in `*tmp*`[[c(1, 1)]]: subscript out of bounds
url_string <- "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Manchester%20Deaf%20Institute&destinations=Birmingham%20O2%20Academy%201&mode=driving&language=en-EN"
connect <- url(url_string)
str(rjson::fromJSON(paste(readLines(connect), collapse = "")))
#> unsupported SEXPTYPE: 19
#> List of 4
#> $ destination_addresses: chr "16-18 Horse Fair, Birmingham B1 1DB, UK"
#> $ origin_addresses : chr "135 Grosvenor St, Manchester M1 7HE, UK"
#> $ rows :List of 1
#> ..$ : NULL
#> $ status : chr "OK"
close(connect)
str(rjson::fromJSON(file = url_string))
#> unsupported SEXPTYPE: 19
#> List of 4
#> $ destination_addresses: chr "16-18 Horse Fair, Birmingham B1 1DB, UK"
#> $ origin_addresses : chr "135 Grosvenor St, Manchester M1 7HE, UK"
#> $ rows :List of 1
#> ..$ : NULL
#> $ status : chr "OK"
str(jsonlite::fromJSON(url_string))
#> List of 4
#> $ destination_addresses: chr "16-18 Horse Fair, Birmingham B1 1DB, UK"
#> $ origin_addresses : chr "135 Grosvenor St, Manchester M1 7HE, UK"
#> $ rows :'data.frame': 1 obs. of 1 variable:
#> ..$ elements:List of 1
#> .. ..$ :'data.frame': 1 obs. of 3 variables:
#> .. .. ..$ distance:'data.frame': 1 obs. of 2 variables:
#> .. .. .. ..$ text : chr "141 km"
#> .. .. .. ..$ value: int 141330
#> .. .. ..$ duration:'data.frame': 1 obs. of 2 variables:
#> .. .. .. ..$ text : chr "1 hour 50 mins"
#> .. .. .. ..$ value: int 6576
#> .. .. ..$ status : chr "OK"
#> $ status : chr "OK"
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.5.0 Patched (2018-05-03 r74699)
#> system x86_64, mingw32
#> ui RTerm
#> language en
#> collate Finnish_Finland.1252
#> tz Europe/Helsinki
#> date 2018-05-08
#> Packages -----------------------------------------------------------------
#> package * version date source
#> assertthat 0.2.0 2017-04-11 CRAN (R 3.5.0)
#> backports 1.1.2 2017-12-13 CRAN (R 3.5.0)
#> base * 3.5.0 2018-05-06 local
#> bindr 0.1.1 2018-03-13 CRAN (R 3.5.0)
#> bindrcpp 0.2.2 2018-03-29 CRAN (R 3.5.0)
#> bitops 1.0-6 2013-08-17 CRAN (R 3.5.0)
#> colorspace 1.3-2 2016-12-14 CRAN (R 3.5.0)
#> compiler 3.5.0 2018-05-06 local
#> curl 3.2 2018-03-28 CRAN (R 3.5.0)
#> datasets * 3.5.0 2018-05-06 local
#> devtools 1.13.5 2018-02-18 CRAN (R 3.5.0)
#> digest 0.6.15 2018-01-28 CRAN (R 3.5.0)
#> dplyr 0.7.4 2017-09-28 CRAN (R 3.5.0)
#> evaluate 0.10.1 2017-06-24 CRAN (R 3.5.0)
#> formatR 1.5 2017-04-25 CRAN (R 3.5.0)
#> ggmap * 2.7.900 2018-05-02 Github (dkahle/ggmap@1c2fb46)
#> ggplot2 * 2.2.1.9000 2018-05-02 Github (thomasp85/ggplot2@f1ba983)
#> glue 1.2.0 2017-10-29 CRAN (R 3.5.0)
#> graphics * 3.5.0 2018-05-06 local
#> grDevices * 3.5.0 2018-05-06 local
#> grid 3.5.0 2018-05-06 local
#> gtable 0.2.0 2016-02-26 CRAN (R 3.5.0)
#> htmltools 0.3.6 2017-04-28 CRAN (R 3.5.0)
#> jpeg 0.1-8 2014-01-23 CRAN (R 3.5.0)
#> jsonlite 1.5 2017-06-01 CRAN (R 3.5.0)
#> knitr 1.20 2018-02-20 CRAN (R 3.5.0)
#> lazyeval 0.2.1 2017-10-29 CRAN (R 3.5.0)
#> magrittr 1.5 2014-11-22 CRAN (R 3.5.0)
#> memoise 1.1.0 2017-04-21 CRAN (R 3.5.0)
#> methods * 3.5.0 2018-05-06 local
#> munsell 0.4.3 2016-02-13 CRAN (R 3.5.0)
#> pillar 1.2.2 2018-04-26 CRAN (R 3.5.0)
#> pkgconfig 2.0.1 2017-03-21 CRAN (R 3.5.0)
#> plyr 1.8.4 2016-06-08 CRAN (R 3.5.0)
#> png 0.1-7 2013-12-03 CRAN (R 3.5.0)
#> R6 2.2.2 2017-06-17 CRAN (R 3.5.0)
#> Rcpp 0.12.16 2018-03-13 CRAN (R 3.5.0)
#> RgoogleMaps 1.4.1 2016-09-18 CRAN (R 3.5.0)
#> rjson 0.2.18 2018-05-05 CRAN (R 3.5.0)
#> rlang 0.2.0.9001 2018-05-02 Github (tidyverse/rlang@82b2727)
#> rmarkdown 1.9 2018-03-01 CRAN (R 3.5.0)
#> rprojroot 1.3-2 2018-01-03 CRAN (R 3.5.0)
#> scales 0.5.0.9000 2018-05-02 Github (hadley/scales@d767915)
#> stats * 3.5.0 2018-05-06 local
#> stringi 1.2.2 2018-05-02 CRAN (R 3.5.0)
#> stringr 1.3.0 2018-02-19 CRAN (R 3.5.0)
#> tibble 1.4.2 2018-01-22 CRAN (R 3.5.0)
#> tools 3.5.0 2018-05-06 local
#> utils * 3.5.0 2018-05-06 local
#> withr 2.1.2 2018-05-02 Github (jimhester/withr@79d7b0d)
#> yaml 2.1.19 2018-05-01 CRAN (R 3.5.0)
@mvkorpel you're right. Upgrading rjson broke it.
library(ggmap)
#> Loading required package: ggplot2
#> Google Maps API Terms of Service: http://developers.google.com/maps/terms.
#> Please cite ggmap if you use it: see citation("ggmap") for details.
mapdist("Manchester Deaf Institute", "Birmingham O2 Academy 1", mode = "driving")
#> unsupported SEXPTYPE: 19
#> Source : https://maps.googleapis.com/maps/api/distancematrix/json?origins=Manchester%20Deaf%20Institute&destinations=Birmingham%20O2%20Academy%201&mode=driving&language=en-EN
#> Error in `*tmp*`[[c(1, 1)]]: subscript out of bounds
Session info
devtools::session_info()
#> Warning in as.POSIXlt.POSIXct(Sys.time()): unknown timezone 'zone/tz/2018c.
#> 1.0/zoneinfo/America/New_York'
#> ─ Session info ──────────────────────────────────────────────────────────
#> setting value
#> version R version 3.3.3 (2017-03-06)
#> os macOS 10.13.4
#> system x86_64, darwin13.4.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> tz <NA>
#> date 2018-05-08
#>
#> ─ Packages ──────────────────────────────────────────────────────────────
#> package * version date source
#> assertthat 0.2.0 2017-04-11 cran (@0.2.0)
#> backports 1.1.2 2017-12-13 cran (@1.1.2)
#> bindr 0.1 2016-11-13 cran (@0.1)
#> bindrcpp 0.2 2017-06-17 CRAN (R 3.3.2)
#> bitops 1.0-6 2013-08-17 CRAN (R 3.3.0)
#> callr 2.0.1 2018-01-30 CRAN (R 3.3.3)
#> cli 1.0.0 2017-11-05 cran (@1.0.0)
#> clisymbols 1.2.0 2017-05-21 cran (@1.2.0)
#> colorspace 1.3-2 2016-12-14 CRAN (R 3.3.2)
#> crayon 1.3.4 2018-05-07 Github (r-lib/crayon@95b3eae)
#> debugme 1.1.0 2017-10-22 CRAN (R 3.3.2)
#> desc 1.1.1 2017-08-03 CRAN (R 3.3.2)
#> devtools 1.13.5.9000 2018-02-22 Github (hadley/devtools@c890eaf)
#> digest 0.6.13 2017-12-14 cran (@0.6.13)
#> dplyr 0.7.4 2017-09-28 cran (@0.7.4)
#> evaluate 0.10.1 2017-06-24 cran (@0.10.1)
#> formatR 1.5 2017-04-25 CRAN (R 3.3.2)
#> ggmap * 2.7.900 2018-05-07 Github (dkahle/ggmap@1c2fb46)
#> ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.3.2)
#> glue 1.2.0 2017-10-29 cran (@1.2.0)
#> gtable 0.2.0 2016-02-26 CRAN (R 3.3.0)
#> htmltools 0.3.6 2017-04-28 cran (@0.3.6)
#> jpeg 0.1-8 2014-01-23 CRAN (R 3.3.0)
#> knitr 1.20 2018-03-30 Github (yihui/knitr@03b6e40)
#> lazyeval 0.2.1 2017-10-29 CRAN (R 3.3.2)
#> magrittr 1.5 2014-11-22 CRAN (R 3.3.0)
#> memoise 1.1.0 2017-04-21 CRAN (R 3.3.2)
#> munsell 0.4.3 2016-02-13 CRAN (R 3.3.0)
#> pillar 1.2.2 2018-05-07 Github (hadley/colformat@534f7e8)
#> pkgbuild 0.0.0.9000 2018-02-22 Github (r-lib/pkgbuild@4a85872)
#> pkgconfig 2.0.1 2017-03-21 cran (@2.0.1)
#> pkgload 0.0.0.9000 2018-02-22 Github (r-lib/pkgload@884e79d)
#> plyr 1.8.4 2016-06-08 CRAN (R 3.3.0)
#> png 0.1-7 2013-12-03 CRAN (R 3.3.0)
#> R6 2.2.2 2017-06-17 cran (@2.2.2)
#> Rcpp 0.12.14 2017-11-23 cran (@0.12.14)
#> RgoogleMaps 1.4.1 2016-09-18 CRAN (R 3.3.0)
#> rjson 0.2.18 2018-05-05 CRAN (R 3.3.3)
#> rlang 0.2.0.9001 2018-05-07 Github (tidyverse/rlang@1da4a6a)
#> rmarkdown 1.9.8 2018-03-30 Github (rstudio/rmarkdown@8cfc878)
#> rprojroot 1.3-2 2018-01-03 cran (@1.3-2)
#> scales 0.5.0.9000 2018-05-07 Github (hadley/scales@d767915)
#> sessioninfo 1.0.0 2017-06-21 cran (@1.0.0)
#> stringi 1.1.6 2017-11-17 cran (@1.1.6)
#> stringr 1.3.0 2018-02-19 cran (@1.3.0)
#> testthat 2.0.0 2017-12-13 cran (@2.0.0)
#> tibble 1.4.2.9001 2018-05-07 Github (hadley/tibble@b90a4fd)
#> usethis 1.1.0 2017-11-17 cran (@1.1.0)
#> withr 2.1.2 2018-04-30 Github (jimhester/withr@79d7b0d)
#> yaml 2.1.16 2017-12-12 cran (@2.1.16)
We'll need to poke at this sometime but it sounds like the workaround for now is installing rjson version 0.2.15
devtools::install_version("rjson", version = "0.2.15")
Hello, unfortunately the workaround () does not help me. Does anyone have an idea that can help me?
library(ggmap)
#> Lade nötiges Paket: ggplot2
mapdist("Manchester Deaf Institute", "Birmingham O2 Academy 1", mode = "driving")
#> by using this function you are agreeing to the terms at :
#> http://code.google.com/apis/maps/documentation/distancematrix/
#> Information from URL : http://maps.googleapis.com/maps/api/distancematrix/json?origins=Manchester+Deaf+Institute&destinations=Birmingham+O2+Academy+1&mode=driving&sensor=false
#> from to m km miles
#> 1 Manchester Deaf Institute Birmingham O2 Academy 1 141330 141.33 87.82246
#> seconds minutes hours
#> 1 6569 109.4833 1.824722
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.5.0 (2018-04-23)
#> system x86_64, darwin15.6.0
#> ui X11
#> language (EN)
#> collate de_DE.UTF-8
#> tz Europe/Berlin
#> date 2018-05-11
#> Packages -----------------------------------------------------------------
#> package * version date source
#> backports 1.1.2 2017-12-13 CRAN (R 3.5.0)
#> base * 3.5.0 2018-04-24 local
#> colorspace 1.3-2 2016-12-14 CRAN (R 3.5.0)
#> compiler 3.5.0 2018-04-24 local
#> datasets * 3.5.0 2018-04-24 local
#> devtools 1.13.5 2018-02-18 CRAN (R 3.5.0)
#> digest 0.6.15 2018-01-28 CRAN (R 3.5.0)
#> evaluate 0.10.1 2017-06-24 CRAN (R 3.5.0)
#> geosphere 1.5-7 2017-11-05 CRAN (R 3.5.0)
#> ggmap * 2.6.1 2016-01-23 CRAN (R 3.5.0)
#> ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.5.0)
#> graphics * 3.5.0 2018-04-24 local
#> grDevices * 3.5.0 2018-04-24 local
#> grid 3.5.0 2018-04-24 local
#> gtable 0.2.0 2016-02-26 CRAN (R 3.5.0)
#> htmltools 0.3.6 2017-04-28 CRAN (R 3.5.0)
#> jpeg 0.1-8 2014-01-23 CRAN (R 3.5.0)
#> knitr 1.20 2018-02-20 CRAN (R 3.5.0)
#> lattice 0.20-35 2017-03-25 CRAN (R 3.5.0)
#> lazyeval 0.2.1 2017-10-29 CRAN (R 3.5.0)
#> magrittr 1.5 2014-11-22 CRAN (R 3.5.0)
#> mapproj 1.2.6 2018-03-29 CRAN (R 3.5.0)
#> maps 3.3.0 2018-04-03 CRAN (R 3.5.0)
#> memoise 1.1.0 2017-04-21 CRAN (R 3.5.0)
#> methods * 3.5.0 2018-04-24 local
#> munsell 0.4.3 2016-02-13 CRAN (R 3.5.0)
#> pillar 1.2.2 2018-04-26 CRAN (R 3.5.0)
#> plyr 1.8.4 2016-06-08 CRAN (R 3.5.0)
#> png 0.1-7 2013-12-03 CRAN (R 3.5.0)
#> proto 1.0.0 2016-10-29 CRAN (R 3.5.0)
#> Rcpp 0.12.16 2018-03-13 CRAN (R 3.5.0)
#> reshape2 1.4.3 2017-12-11 CRAN (R 3.5.0)
#> RgoogleMaps 1.4.1 2016-09-18 CRAN (R 3.5.0)
#> rjson 0.2.15 2014-11-03 url
#> rlang 0.2.0 2018-02-20 CRAN (R 3.5.0)
#> rmarkdown 1.9 2018-03-01 CRAN (R 3.5.0)
#> rprojroot 1.3-2 2018-01-03 CRAN (R 3.5.0)
#> scales 0.5.0 2017-08-24 CRAN (R 3.5.0)
#> sp 1.2-7 2018-01-19 CRAN (R 3.5.0)
#> stats * 3.5.0 2018-04-24 local
#> stringi 1.2.2 2018-05-02 CRAN (R 3.5.0)
#> stringr 1.3.1 2018-05-10 CRAN (R 3.5.0)
#> tibble 1.4.2 2018-01-22 CRAN (R 3.5.0)
#> tools 3.5.0 2018-04-24 local
#> utils * 3.5.0 2018-04-24 local
#> withr 2.1.2 2018-03-15 CRAN (R 3.5.0)
#> yaml 2.1.19 2018-05-01 CRAN (R 3.5.0)
@hueck83 I'm confused. Where is the error you're encountering?
@hueck83 I couldn't see the problem as @scottmmjackson mentioned.
Anyway, for me the rjson downgrade worked, and I think the the bug is when fromJSON needs to read a { character.
Unfortunately, for a colleague of my team, the older rjson package throws another error. But I could make the newest rjson::fromJSON() to work with the argument method="R". As I understood from documentation, it uses an R version of the function, that doesn't have the bug.
@karina-rebuli thanks for that! where do you use "method="R"? I see that is in fromJSON but how do you use that with mapdist?