Mount Google Drive to Google Colab
We often need to read some data files into R, and it is a bit tricky with google colab as it doesn't have access to the files saved in your local drive.
The solution is to upload the date files to your google drive. I highly recommend you open a new google account designated for this class only (or your other school work) so that they don't get mixed up with your personal stuff.
We still need to take a few extra steps, but fortunately I believe that you only need to do this once, or once a while.
Here is the tricky part. Although we only want to use R, we need to run some Python code first to mount google drive.
First make sure that you change the runtime to Python 3, then run the code below,
Now we are done. Change the runtime back to R, and it can access files in your google drive following the path "/content/drive/MyDrive/". As far as I can tell, google drive will stay mounted for a while even when you leave and go back to google colab. In case the connection is lost, just run it again.
For your convenience, I shared a notebook file that contains the above codes, Click on the link below, it should automatically show up in your google colab.
Comments
Post a Comment