如何在 RStudio 中保存和共用程式碼How to persist and share code in RStudio

問題Problem

不同于具有內建版本控制的 Azure Databricks 筆記本,在裝載 Rstudio 的高平行存取叢集關閉時,RStudio 中開發的程式碼會遺失。Unlike a Azure Databricks notebook that has version control built in, code developed in RStudio is lost when the high concurrency cluster hosting Rstudio is shut down.

解決方法Solution

若要在 RStudio 中保存及共用程式碼,請執行下列其中一項動作:To persist and share code in RStudio, do one of the following:

  • 從 RStudio,將程式碼儲存到 DBFS 上的資料夾,這可從 Azure Databricks 筆記本和 RStudio 存取。From RStudio, save the code to a folder on DBFS which is accessible from both Azure Databricks notebooks and RStudio.
  • 在 RStudio 中使用版本控制的整合支援,例如 Git。Use the integrated support for version control like Git in RStudio.
  • 將 R 筆記本儲存到本機檔案系統,方法是將它匯出為,然後將檔案匯 Rmarkdown 入至 RStudio 實例。Save the R notebook to your local file system by exporting it as Rmarkdown, then import the file into the RStudio instance.

使用 RMarkdown 共用 R 筆記本的 blog 會更詳細地說明這些步驟。The blog Sharing R Notebooks using RMarkdown describes the steps in more detail.

此程式可讓您保存在 RStudio 中開發的程式碼,並在 Azure Databricks 筆記本環境和 RStudio 之間共用筆記本。This process allows you to persist code developed in RStudio and share notebooks between the Azure Databricks notebook environment and RStudio.