Skip to content

Commit 4be60d9

Browse files
authored
Update how-to-r-interactive-development.md
Added an additional example that uses Datastore URI and does not use Pandas.
1 parent 811807c commit 4be60d9

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

articles/machine-learning/how-to-r-interactive-development.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.devlang: r
1212
---
1313

1414
# Interactive R development
15-
15+
1616
[!INCLUDE [dev v2](../../includes/machine-learning-dev-v2.md)]
1717

1818
This article will show you how to use R on a compute instance in Azure Machine Learning studio, running an R kernel in a Jupyter notebook.
@@ -52,7 +52,7 @@ Your notebook is now ready for you to run R commands.
5252

5353
You can upload files to your workspace file storage and access them in R. But for files stored in Azure [_data assets_ or data from _datastores_](concept-data.md), you first need to install a few packages.
5454

55-
This section describes how to use Python and the `reticulate` package to load your data assets and datastores into R from an interactive session. You'll read tabular data as Pandas DataFrames using the [`azureml-fsspec`](/python/api/azureml-fsspec/?view=azure-ml-py&preserve-view=true) Python package and the `reticulate` R package.
55+
This section describes how to use Python and the `reticulate` package to load your data assets and datastores into R from an interactive session. You'll read tabular data as Pandas DataFrames using the [`azureml-fsspec`](/python/api/azureml-fsspec/?view=azure-ml-py&preserve-view=true) Python package and the `reticulate` R package. There is also an example of reading this into a R `data.frame`.
5656

5757
To install these packages:
5858

@@ -72,7 +72,7 @@ The install script performs the following steps:
7272

7373
### Read tabular data from registered data assets or datastores
7474

75-
When your data is stored in a data asset [created in Azure Machine Learning](how-to-create-data-assets.md?tabs=cli#create-a-file-asset), use these steps to read that tabular file into an R `data.frame`:
75+
When your data is stored in a data asset [created in Azure Machine Learning](how-to-create-data-assets.md?tabs=cli#create-a-file-asset), use these steps to read that tabular file into a Pandas DataFrame or an R `data.frame`:
7676
> [!NOTE]
7777
> Reading a file with `reticulate` only works with tabular data.
7878
@@ -108,6 +108,40 @@ When your data is stored in a data asset [created in Azure Machine Learning](how
108108
109109
[!Notebook-r[](~/azureml-examples-mavaisma-r-azureml/tutorials/using-r-with-azureml/02-develop-in-interactive-r/work-with-data-assets.ipynb?name=read-uri)]
110110
111+
Alternatively, you can use a Datastore URI to access different files on a registed Datastore, and read this into an R `data.frame`.
112+
113+
1. Create a Datastore URI, using your own values in the following format:
114+
```r
115+
subscription <- '<subscription_id>'
116+
resource_group <- '<resource_group>'
117+
workspace <- '<workspace>'
118+
datastore_name <- '<datastore>'
119+
path_on_datastore <- '<path>'
120+
121+
uri <- paste0("azureml://subscriptions/", subscription, "/resourcegroups/", resource_group, "/workspaces/", workspace, "/datastores/", datastore_name, "/paths/", path_on_datastore)
122+
```
123+
124+
> [!TIP]
125+
> Rather than remember the datastore URI format, you can copy-and-paste the datastore URI from the Studio UI by following these steps:
126+
> 1. Select **Data** from the left-hand menu followed by the **Datastores** tab.
127+
> 1. Select your datastore name and then **Browse**.
128+
> 1. Find the file/folder you want to read into R, select the elipsis (**...**) next to it. Select from the menu **Copy URI**. You can select the **Datastore URI** to copy into your notebook/script. Please note, you will still need too create a variable for "<path>".
129+
> :::image type="content" source="media/how-to-access-data-ci/datastore_uri_copy.png" alt-text="Screenshot highlighting the copy of the datastore URI.":::
130+
131+
2. Create a filestore object using the aforementioned URI:
132+
```r
133+
fs <- azureml.fsspec$AzureMachineLearningFileSystem(uri, sep = "")
134+
```
135+
136+
3. Read into a R `data.frame`:
137+
```r
138+
df <- with(fs$open("<path>)", "r") %as% f, {
139+
x <- as.character(f$read(), encoding = "utf-8")
140+
read.csv(textConnection(x), header = TRUE, sep = ",", stringsAsFactors = FALSE)
141+
})
142+
print(df)
143+
```
144+
111145
## Install R packages
112146
113147
There are many R packages pre-installed on the compute instance.
@@ -156,4 +190,4 @@ Other than the above issues, use R as you would in any other environment, such a
156190
157191
## Next steps
158192

159-
* [Adapt your R script to run in production](how-to-r-modify-script-for-production.md)
193+
* [Adapt your R script to run in production](how-to-r-modify-script-for-production.md)

0 commit comments

Comments
 (0)