在 R 中从 HTTPS 下载数据

bit*_*tap 3 https r download

我在 R 中从 HTTPS 下载数据时遇到问题,我尝试使用curl,但它不起作用。

URL <- "https://github.com/Bitakhparsa/Capstone/blob/0850c8f65f74c58e45f6cdb2fc6d966e4c160a78/Plant_1_Generation_Data.csv"

options('download.file.method'='curl')
download.file(URL, destfile = "./data.csv", method="auto")
Run Code Online (Sandbox Code Playgroud)

我使用该代码下载了 CSV 文件,但当我检查数据时格式发生了变化。所以没有正确下载。请有人帮助我吗?

neu*_*ron 5

我认为您实际上可能输入了错误的网址。我想你想要:

https://raw.githubusercontent.com/Bitakhparsa/Capstone/0850c8f65f74c58e45f6cdb2fc6d966e4c160a78/Plant_1_Generation_Data.csv

然后您可以直接使用下载文件,library(RCurl)而不是使用 URL 创建变量

library(RCurl)
download.file("https://raw.githubusercontent.com/Bitakhparsa/Capstone/0850c8f65f74c58e45f6cdb2fc6d966e4c160a78/Plant_1_Generation_Data.csv",destfile="./data.csv",method="libcurl")
Run Code Online (Sandbox Code Playgroud)

您还可以使用以下命令将文件直接从站点加载到 R 中

URL <- "https://github.com/Bitakhparsa/Capstone/blob/0850c8f65f74c58e45f6cdb2fc6d966e4c160a78/Plant_1_Generation_Data.csv"
out <- read.csv(textConnection(URL))
Run Code Online (Sandbox Code Playgroud)