I have an R notebook in colab where I want to read a file which is saved in my google drive.
I only seem to find python code such as \"from google.colab import driv
Start using python:
from google.colab import drive
drive.mount('/content/drive')
Then load the R Magic:
%load_ext rpy2.ipython
and then activate the R Magic and load your data:
%%R
url = ('/content/drive/myDrive/folder1/myfile.csv')
dataset = read.csv(url)
It seems there is no mechanism as of now to mount google drive in colab notebook with R kernel. Although a workaround can be used to have google drive mounted normally as in pyhton kernel and use both python and r based on the needs. See this answer which explains how r and python can be run together.
# activate R magic
%load_ext rpy2.ipython
%%R
x <- 42
print(x)
To mount google drive in an R kernel:
install.packages("googledrive")
library("googledrive")
if (file.exists("/usr/local/lib/python3.6/dist-packages/google/colab_ipython.py")){
install.packages("R.utils")
library("R.utils")
library("httr")
my_check <- function() {return(TRUE)}
reassignInPackage("is_interactive", pkgName = "httr", my_check)
options(rlang_interactive=TRUE)
}
And authenticate google drive
drive_auth(use_oob = TRUE, cache = TRUE)