You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R内核的Google Colab笔记本中导入私有数据

Mounting Google Drive in R Kernel Google Colab Notebooks

Great question! It’s totally possible to mount your Google Drive in an R kernel Colab notebook—you just need to work around the Python-focused default tools. Here are two straightforward, reliable methods:

Method 1: Use reticulate to Call Colab’s Python Mount Function

Colab’s R environment comes pre-installed with the reticulate package, which lets you interface directly with Python code. This means you can use the official Google Drive mount function without switching kernels:

# Load the reticulate package (pre-installed in Colab R)
library(reticulate)

# Import Colab's drive module
drive <- import("google.colab.drive")

# Trigger the mount process
drive$mount("/content/drive")

When you run this code, you’ll see the same authorization prompt as in a Python kernel:

  1. Click the generated link to sign in to your Google account.
  2. Copy the authorization code.
  3. Paste it back into the Colab input box and press Enter.

Once authorized, your Drive will be mounted at /content/drive/MyDrive—you can access files using standard R file functions like read.csv(), list.files(), etc.

Method 2: Use Colab Magic Commands to Run Python Mount Code

Colab’s R kernel supports IPython-style magic commands, so you can directly run the standard Python mount code with the %python magic:

# Run Python's Drive mount code via magic command
%python
from google.colab import drive
drive.mount('/content/drive')

This method is even simpler—you’re reusing the exact same code from Python kernels, just wrapped in the magic command to execute it in the Python runtime alongside your R session. The authorization steps are identical to Method 1.

Verify the Mount

To confirm your Drive is mounted correctly, run this R code to list files in your Drive’s root:

# List files in your Google Drive root
list.files("/content/drive/MyDrive")

Either method will give you full access to your private data in the R kernel, so you can read/write files just like you would with local storage.

内容的提问来源于stack exchange,提问作者Parseltongue

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 21:02:48