Ошибка в readChar(con, 5L, useBytes = TRUE): не удается открыть соединение
'mow.R
'теперь содержит:
library(RgoogleMaps);
png(filename="RgoogleMaps-package_%03d_med.png", width=480, height=480);
MyMap <- GetMap(markers='&40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc', destfile="MyTile1.png");
Это приводит к следующей новой ошибке:
> source('mow.R')
[1] "Note that when center and zoom are not specified, no meta information on the map tile can be stored. This basically means that R cannot compute proper coordinates. You can still download the map tile and view it in R but overlays are not possible. Do you want to proceed ? (y/n)"
y
[1] "&40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc"
[1] "http://maps.google.com/maps/api/staticmap?size=640x640&maptype=terrain&format=png32&sensor=true&40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc"
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
cannot open compressed file 'MyTile1.png.rda', probable reason 'No such file or directory'
>
Как исправить эту ошибку?
Версия R 2.15.1
RgoogleMaps версия 1.2.0
> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RgoogleMaps_1.2.0 png_0.1-4
>
2 ответа
Решение
Решаемые. Вот рабочий код:
library(RgoogleMaps);
png(filename="Rg.png", width=480, height=480);
lat = c(40.702147,40.718217,40.711614);
lon = c(-74.012318,-74.015794,-73.998284);
center = c(mean(lat), mean(lon));
zoom <- min(MaxZoom(range(lat), range(lon)));
MyMap <- GetMap(center=center, zoom=zoom, markers='&40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc', destfile="My.png");
tmp <- PlotOnStaticMap(MyMap,lat=c(40.702147,40.711614,40.718217),lon=c(-74.015794,-74.012318,-73.998284),cex=1.5,pch=20,col=c('red', 'blue', 'green'),add=F);
dev.off();
Это приводит к:
anisha@linux-y3pi:~/RTest> ls
new.R
anisha@linux-y3pi:~/RTest> R
R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
[Previously saved workspace restored]
> source('new.R')
Loading required package: png
[1] "&40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc"
[1] "http://maps.google.com/maps/api/staticmap?center=40.7106593333333,-74.0087986666667&zoom=15&size=640x640&maptype=terrain&format=png32&sensor=true&40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc"
> q()
Save workspace image? [y/n/c]: y
anisha@linux-y3pi:~/RTest> ls
My.png My.png.rda new.R Rg.png
anisha@linux-y3pi:~/RTest>
2 распространенные причины
- Файл не существует
- В пути к файлу опечатка.
Оба приведут к ошибке:
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
cannot open file
но однажды исправленный,load()
будет работать так, как ожидалось.
Некоторые советы, которые могут помочь
- Убедитесь, что у вас нет опечаток в пути к файлу
- Убедитесь, что у вас есть полное имя файла (например,
birds.rda
) - Если вы укажете относительный путь, запустите
getwd()
чтобы убедиться, что относительный путь относится к вашему текущему рабочему каталогу. (если нет, измените либо относительный путь, либо текущий рабочий каталог с помощьюsetwd()
)