Skip to content

Commit d842110

Browse files
authored
Merge pull request #232942 from mgladwell/main
Update how-to-r-interactive-development.md
2 parents 0c705f1 + fe16ead commit d842110

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

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

Lines changed: 41 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,43 @@ 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 registered 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+
115+
```r
116+
subscription <- '<subscription_id>'
117+
resource_group <- '<resource_group>'
118+
workspace <- '<workspace>'
119+
datastore_name <- '<datastore>'
120+
path_on_datastore <- '<path>'
121+
122+
uri <- paste0("azureml://subscriptions/", subscription, "/resourcegroups/", resource_group, "/workspaces/", workspace, "/datastores/", datastore_name, "/paths/", path_on_datastore)
123+
```
124+
125+
> [!TIP]
126+
> Rather than remember the datastore URI format, you can copy-and-paste the datastore URI from the Studio UI, if you know the datastore where your file is located:
127+
> 1. Navigate to the file/folder you want to read into R
128+
> 1. Select the elipsis (**...**) next to it.
129+
> 1. Select from the menu **Copy URI**.
130+
> 1. Select the **Datastore URI** to copy into your notebook/script.
131+
> Please note, you will still need to create a variable for `<path>` in the code.
132+
> :::image type="content" source="media/how-to-access-data-ci/datastore_uri_copy.png" alt-text="Screenshot highlighting the copy of the datastore URI.":::
133+
134+
2. Create a filestore object using the aforementioned URI:
135+
```r
136+
fs <- azureml.fsspec$AzureMachineLearningFileSystem(uri, sep = "")
137+
```
138+
139+
3. Read into a R `data.frame`:
140+
```r
141+
df <- with(fs$open("<path>)", "r") %as% f, {
142+
x <- as.character(f$read(), encoding = "utf-8")
143+
read.csv(textConnection(x), header = TRUE, sep = ",", stringsAsFactors = FALSE)
144+
})
145+
print(df)
146+
```
147+
111148
## Install R packages
112149
113150
There are many R packages pre-installed on the compute instance.
@@ -156,4 +193,4 @@ Other than the above issues, use R as you would in any other environment, such a
156193
157194
## Next steps
158195

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

0 commit comments

Comments
 (0)