ggmap's get_map returns 'Error in gzfile(file, "rb") : cannot open the connection'
Asked Answered
A

3

7

I have some R code to plot data on maps with ggmap. It was working fine last week. However, now when I run the line to get the map:

emap <- get_map(c(-2.503704,43.18735),zoom=9,maptype="roadmap",color="bw")  

I get the following error:

Error in gzfile(file, "rb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "rb") :
  cannot open compressed file '/var/folders/2w/2wSOAL2LFUC+2QkRaR1wI++++TI/-Tmp-//Rtmpj0TMx5/ggmap/index.rds', probable reason 'No such file or directory'

I have searched this forum and the web but can't find any other threads discussing this error.

Any help is much appreciated. Regards, Noelia

PS: sessionInfo() returns the following:

R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] mapproj_1.2-2  maps_2.3-9     ggmap_2.4      dplyr_0.4.1        xtable_1.7-4   ggplot2_1.0.1  reshape2_1.4.1

loaded via a namespace (and not attached):
[1] assertthat_0.1      colorspace_1.2-6    DBI_0.3.1           digest_0.6.8        geosphere_1.3-13    grid_3.1.2         
[7] gtable_0.1.2        jpeg_0.1-8          labeling_0.3        lattice_0.20-31     lazyeval_0.1.10     magrittr_1.5       
[13] MASS_7.3-40         munsell_0.4.2       parallel_3.1.2      plyr_1.8.1          png_0.1-7           proto_0.3-10       
[19] Rcpp_0.11.5         RgoogleMaps_1.2.0.7 rjson_0.2.15        RJSONIO_1.3-0       scales_0.2.4        sp_1.0-17          
[25] stringr_0.6.2       tools_3.1.2  
Airfield answered 28/8, 2015 at 11:48 Comment(5)
Your code works fine for me. Could you post the output of sessionInfo()?Monoplegia
Works for me. Does this work? get_map(location="New York, NY",zoom=9,maptype="roadmap",color="bw") or try defining the source=Rainfall
@PierreLafortune I have tried the line you suggest. That doesn't work for me either, I get the same error. Plus I get the same error specifying the source for all google, osm and stamenAirfield
I cleared the environment and closed the project and RStudio. Then, opened everything again and get_map was working again!Airfield
Has anyone discovered the reason for this error? Restarting R worked for me, but it would be nice to know the source of the problem.Screwworm
J
4

I've experienced the same error, with code that had also previously worked. You may have already tried this, but I resolved it by simply ending the R session and restarting it.

If this does not work, try uninstalling/reinstalling R(Studio), or at least the packages involved.

Jasperjaspers answered 9/1, 2017 at 16:51 Comment(0)
M
2

if you save your files as RData, even you can open it in R but sometimes it is corrupted, you have to run all those variable in formula again and then you can run your code properly. its because in your formula you have a variable that is not accessible by the computer.

Manutius answered 4/5, 2017 at 10:13 Comment(1)
This not reflects on the problem mentioned in the question. It is only a recommendation for saving the calculated results (to evite doing the same work twice in case of restarting the R-session).Rms
K
1

Same issue was happening to me. I use R version 3.4.2, and RStudio Version 1.1.383. I restarted RStudio, and it fixed the issue.

Keister answered 13/12, 2017 at 19:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.