Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R如何使用R从google drive读取文件_R_Url_Dataset - Fatal编程技术网

R如何使用R从google drive读取文件

R如何使用R从google drive读取文件,r,url,dataset,R,Url,Dataset,我想在R中读取来自GoogleDrive的数据集作为 表明 都不是 url <- "https://drive.google.com/file/d/1AiZda_1-2nwrxI8fLD0Y6e5rTg7aocv0" temp <- tempfile() download.file(url, temp) bank <- read.table(unz(temp, "bank-additional.csv")) unlink(temp) url试试看 google驱动器共享链接

我想在R中读取来自GoogleDrive的数据集作为 表明

都不是

url <- "https://drive.google.com/file/d/1AiZda_1-2nwrxI8fLD0Y6e5rTg7aocv0"
temp <- tempfile()
download.file(url, temp)
bank <- read.table(unz(temp, "bank-additional.csv"))
unlink(temp)
url试试看

  • google驱动器共享链接不是直接的文件链接,因此
    1。下载.文件
    2。RCurl
    接受答案中的第一种方法
    仅下载显示文件的网页,而不是文件本身。您可以编辑下载的文件,并看到它是一个html文件

  • 您可以通过查找文件的实际直接链接。通过直接链接,所有常规下载方法都可以正常工作

  • 有关获取或下载直接链接的详细讨论,请参阅

  • googledrive api要求客户端登录,所以googledrive包还要求您在尚未登录的情况下登录Google


使用tidyverse上的
googledrive
库怎么样?谢谢你的回复。第二种方法非常有效。但对于第一种方法,当我用完
library(RCurl)
bank_url <- dowload.file(url, "bank-additional.csv", method = 'curl')
temp <- tempfile(fileext = ".zip")
download.file("https://drive.google.com/uc?authuser=0&id=1AiZda_1-2nwrxI8fLD0Y6e5rTg7aocv0&export=download",
  temp)
out <- unzip(temp, exdir = tempdir())
bank <- read.csv(out[14], sep = ";")
str(bank)
# 'data.frame': 4119 obs. of  21 variables:
 # $ age           : int  30 39 25 38 47 32 32 41 31 35 ...
 # $ job           : Factor w/ 12 levels "admin.","blue-collar",..: 2 8 8 8 1 8 1 3 8 2 ...
 # $ marital       : Factor w/ 4 levels "divorced","married",..: 2 3 2 2 2 3 3 2 1 2 ...
 # <snip>
library(googledrive)
temp <- tempfile(fileext = ".zip")
dl <- drive_download(
  as_id("1AiZda_1-2nwrxI8fLD0Y6e5rTg7aocv0"), path = temp, overwrite = TRUE)
out <- unzip(temp, exdir = tempdir())
bank <- read.csv(out[14], sep = ";")