Last active
September 29, 2021 04:07
-
-
Save tetlabo/7a449d1c097ee2e4b756144304ecb65f to your computer and use it in GitHub Desktop.
Google ColabでRを使いDriveにアクセスする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 必要なパッケージのインストール | |
install.packages("tidyverse") | |
install.packages("googledrive") | |
install.packages("R.utils") | |
# パッケージの読み込み | |
library(tidyverse) | |
library(googledrive) | |
# 非対話モードでのGoogle Drive認証 | |
# https://towardsdatascience.com/how-to-use-r-in-google-colab-b6e02d736497 | |
suppressMessages(library("R.utils")) # 冗長なメッセージが表示されるので抑制 | |
library("httr") | |
my_check <- function() {return(TRUE)} | |
reassignInPackage("is_interactive", pkgName = "httr", my_check) | |
options(rlang_interactive=TRUE) | |
drive_auth(use_oob = TRUE, cache = FALSE) | |
# ドライブの確認 | |
drive_ls("YOUR FOLDER") | |
# ファイルのダウンロード | |
file <- drive_get("YOUR PATH") | |
drive_download(file, overwrite = TRUE) | |
# ダウンロード結果の確認 | |
dir() | |
# ファイルの読み込み | |
df <- read_csv("YOUR FILE NAME") | |
head(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment