本文介绍了R如何使用R从Google驱动器读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以
的形式从Google驱动器中读入R中的数据集指示。

都不是

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)

nor

library(RCurl)
bank_url <- dowload.file(url, "bank-additional.csv", method = 'curl')

工作。

我已经为此工作了好几个小时。任何提示或解决方案都将不胜感激。

I have been working on this for many hours. Any hints or solutions would be really appreciate.

推荐答案

尝试

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>

URL应该对应于您使用浏览器下载文件时使用的URL。

The URL should correspond to the URL that you use to download the file using your browser.

正如@ Mako212指出的那样,您还可以使用 googledrive 包,代替 drive_download 用于 download.file

As @Mako212 points out, you can also make use of the googledrive package, substituting drive_download for download.file:

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 = ";")

这篇关于R如何使用R从Google驱动器读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 07:34