download.file()“无法打开网址”

问题描述 投票:0回答:1

我试图找出这个 URL 有什么问题,或者为什么我的 RStudio 无法访问我可以使用浏览器访问的完美 URL。
此 URL 会自动下载一个

.csv
该代码过去曾为同事工作过。

url <- "http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID=6329&Year=1953&Month=1&Day=1&timeframe=2&submit= Download+Data"

download.file(url,"files.csv",quiet=TRUE)

它抛出的错误是:

Error in download.file(url, "files.csv", quiet = TRUE) : 
  cannot open URL 'http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID=6329&Year=1953&Month=1&Day=1&timeframe=2&submit= Download+Data'

另外:警告信息:

In download.file(url, "files.csv", quiet = TRUE) :
  URL 'http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID=6329&Year=1953&Month=1&Day=1&timeframe=2&submit= Download+Data': status was 'URL using bad/illegal format or missing URL'
r url r-download.file
1个回答
0
投票

从 URL 中删除

submit=
部分。

> url<- "http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID=6329&Year=1953&Month=1&Day=1&timeframe=2"
> tmp <- tempfile()
> download.file(url, tmp, quiet=TRUE)
> read.csv(tmp)[1:3, 1:10]
  Longitude..x. Latitude..y. Station.Name Climate.ID  Date.Time Year Month Day Data.Quality Max.Temp...C.
1        -62.02        45.48 COLLEGEVILLE    8201000 1953-01-01 1953     1   1           NA          -5.6
2        -62.02        45.48 COLLEGEVILLE    8201000 1953-01-02 1953     1   2           NA          -1.1
3        -62.02        45.48 COLLEGEVILLE    8201000 1953-01-03 1953     1   3           NA           4.4
> 
> unlink(tmp)
© www.soinside.com 2019 - 2024. All rights reserved.