我在尝试使用 R 下载文件时遇到问题

I am having trouble trying to download files with R

所以我想尝试一下 Covid 数据分析。我正在尝试重现 I read here.
但是我从一开始就遇到了麻烦:

下载它使用的数据

## source data files
filenames <- c('time_series_covid19_confirmed_global.csv',
'time_series_covid19_deaths_global.csv',
'time_series_covid19_recovered_global.csv')
url.path <- paste0('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/',
'master/csse_covid_19_data/csse_covid_19_time_series/')

## download files to local
download <- function(filename) {
url <- file.path(url.path, filename)
dest <- file.path('./data', filename)
download.file(url, dest)
}
bin <- lapply(filenames, download)

## load data into R
raw.data.confirmed <- read.csv('./data/time_series_covid19_confirmed_global.csv')
raw.data.deaths <- read.csv('./data/time_series_covid19_deaths_global.csv')
raw.data.recovered <- read.csv('./data/time_series_covid19_recovered_global.csv')

运行 此代码给我以下错误:

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file './data/time_series_covid19_confirmed_global.csv': No such file or directory

现在我探索了两个方向:

## fichiers sources
filenames <- c("10-31-2020.csv")
url.path <- paste0("https://github.com/CSSEGISandData/COVID-19",
                   "blob/master/csse_covid_19_data/csse_covid_19_daily_reports")

## download files to local
download <- function(filename) {
  url <- file.path(url.path, filename)
  dest <- file.path('./data', filename)
  download.file(url, dest)
}
bin <- lapply(filenames, download)

但是我得到另一个错误:

 Error in download.file(url, dest) : 
  cannot open destfile './data/10-31-2020.csv', reason 'No such file or directory'
trying URL 'https://github.com/CSSEGISandData/COVID-19blob/master/csse_covid_19_data/csse_covid_19_daily_reports/10-31-2020.csv'
Error in download.file(url, dest) : 
  cannot open URL 'https://github.com/CSSEGISandData/COVID-19blob/master/csse_covid_19_data/csse_covid_19_daily_reports/10-31-2020.csv'
In addition: Warning message:
In download.file(url, dest) :
 
 Error in download.file(url, dest) : 
  cannot open URL 'https://github.com/CSSEGISandData/COVID-19blob/master/csse_covid_19_data/csse_covid_19_daily_reports/10-31-2020.csv'

现在我不确定为什么它会更改错误,因为我认为 download(url,dest) 中的 dest 是本地保存,但不是硬保存 而且我更不确定接下来要检查什么。

我愿意接受任何其他 safer/more 可靠或可复制的方式来下载此文件。 我只是想要一种方法来自动获取每天的新文件(来自 here

您的 dest 文件路径中需要一个尾部斜线:

dest <- file.path('./data/', filename)