How to access a Data asset via R function in Azure Notebook

Wei Zhang 40 Reputation points
2024-03-12T18:58:57.26+00:00

When I tried to access a data asset from R function in Azure Notebook, I failed. But I can access the same data asset in the same Azure Notebook with a python function. My intention is to initialize a mixed Python-R programming script.

Details: Conda environment Python 3.8 - AzureML. All the packaged mentioned below were installed.

## import rpy2 to use R functions
from rpy2.robjects.packages import importr

## import R package 
dt = importr('data.table')

## import Azure packages
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential
from azure.ai.ml.entities import Data
from azure.ai.ml.constants import AssetTypes
import azureml.fsspec


credential = DefaultAzureCredential()

ml_client = MLClient(
    credential=credential,
    subscription_id="*****************",
    resource_group_name="*************",
    workspace_name="*********",
)

## data asset info
data_asset = ml_client.data.get(name="*******", version=**)
print(f"Data asset URI: {data_asset.path}")

When I tried to use a function fread from R-data.table, one error message appeared:

df = dt.fread(data_asset.path)
df.head()

Error Message: RRuntimeError: Error: File 'azureml://subscriptions/....../datastores/....../paths/source/...csv' does not exist or is non-readable.

But when I used a function from Python in the same Azure notebook, I can read the same '.csv' file.

df = pd.read_csv(data_asset.path)
df.head()


Apparently, the data asset is accessible from this Azure notebook. Why cannot I read it through R function? I guess the problem is about the Runtime and Credential, because A "RRuntime" was created for R function in this Python Runtime. If it is the problem, does that mean I should pass the Credential to the "RRuntime"? could someone help me out?

Thank you in advance!

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,337 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,199 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.