Skip to content Skip to sidebar Skip to footer

How To Mount Google Drive To R Notebook In Colab?

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 drive drive.mount('

Solution 1:

Start using python:

from google.colabimport drive
drive.mount('/content/drive')

Then load the R Magic:

%load_ext rpy2.ipython

and then activate the R Magic and load your data:

%%Rurl= ('/content/drive/myDrive/folder1/myfile.csv')
dataset = read.csv(url)

Solution 2:

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 <- 42print(x)

Solution 3:

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)

Post a Comment for "How To Mount Google Drive To R Notebook In Colab?"