在工作室(经典)中迁移“执行 R 脚本”模块Migrate Execute R Script modules in Studio (classic)

本文介绍如何在 Azure 机器学习中重新生成工作室(经典)“执行 R 脚本”模块。In this article, you learn how to rebuild a Studio (classic) Execute R Script module in Azure Machine Learning.

有关从工作室(经典)迁移的详细信息,请参阅迁移概述一文For more information on migrating from Studio (classic), see the migration overview article.

执行 R 脚本Execute R Script

Azure 机器学习设计器现在在 Linux 上运行。Azure Machine Learning designer now runs on Linux. 工作室(经典)在 Windows 上运行。Studio (classic) runs on Windows. 由于平台更改,你必须在迁移过程中调整“执行 R 脚本”,否则管道会失败。Due to the platform change, you must adjust your Execute R Script during migration, otherwise the pipeline will fail.

若要从工作室(经典)中迁移“执行 R 脚本”模块,必须将 maml.mapInputPortmaml.mapOutputPort 接口替换为标准函数。To migrate an Execute R Script module from Studio (classic), you must replace the maml.mapInputPort and maml.mapOutputPortinterfaces with standard functions.

下表总结了对 R 脚本模块的更改:The following table summarizes the changes to the R Script module:

功能Feature 工作室(经典版)Studio (classic) Azure 机器学习设计器Azure Machine Learning designer
脚本接口Script Interface maml.mapInputPortmaml.mapOutputPortmaml.mapInputPort and maml.mapOutputPort 函数接口Function interface
平台Platform WindowsWindows LinuxLinux
可访问 InternetInternet Accessible No Yes
内存Memory 14 GB14 GB 依赖于计算 SKUDependent on Compute SKU

如何更新 R 脚本接口How to update the R script interface

下面是工作室(经典)中的示例“执行 R 脚本” 模块的内容:Here are the contents of a sample Execute R Script module in Studio (classic):

# Map 1-based optional input ports to variables 
dataset1 <- maml.mapInputPort(1) # class: data.frame 
dataset2 <- maml.mapInputPort(2) # class: data.frame 

# Contents of optional Zip port are in ./src/ 
# source("src/yourfile.R"); 
# load("src/yourData.rdata"); 

# Sample operation 
data.set = rbind(dataset1, dataset2); 

 
# You'll see this output in the R Device port. 
# It'll have your stdout, stderr and PNG graphics device(s). 

plot(data.set); 

# Select data.frame to be sent to the output Dataset port 
maml.mapOutputPort("data.set"); 

下面是设计器中的更新内容。Here are the updated contents in the designer. 请注意,已将 maml.mapInputPortmaml.mapOutputPort 替换为标准函数接口 azureml_mainNotice that the maml.mapInputPort and maml.mapOutputPort have been replaced with the standard function interface azureml_main.

azureml_main <- function(dataframe1, dataframe2){ 
    # Use the parameters dataframe1 and dataframe2 directly 
    dataset1 <- dataframe1 
    dataset2 <- dataframe2 

    # Contents of optional Zip port are in ./src/ 
    # source("src/yourfile.R"); 
    # load("src/yourData.rdata"); 

    # Sample operation 
    data.set = rbind(dataset1, dataset2); 


    # You'll see this output in the R Device port. 
    # It'll have your stdout, stderr and PNG graphics device(s). 
    plot(data.set); 

  # Return datasets as a Named List 

  return(list(dataset1=data.set)) 
} 

有关详细信息,请参阅设计器执行 R 脚本模块参考For more information, see the designer Execute R Script module reference.

从 Internet 安装 R 包Install R packages from the internet

Azure 机器学习设计器使你可以直接从 CRAN 安装包。Azure Machine Learning designer lets you install packages directly from CRAN.

这是对工作室(经典)的改进。This is an improvement over Studio (classic). 由于工作室(经典)在不具有 Internet 访问权限的沙盒环境中运行,因此你必须在 zip 包中上传脚本,才能安装更多包。Since Studio (classic) runs in a sandbox environment with no internet access, you had to upload scripts in a zip bundle to install more packages.

使用以下代码在设计器的“执行 R 脚本”模块中安装 CRAN 包:Use the following code to install CRAN packages in the designer's Execute R Script module:

  if(!require(zoo)) { 
      install.packages("zoo",repos = "http://cran.us.r-project.org") 
  } 
  library(zoo) 

后续步骤Next steps

本文介绍了如何将执行 R 脚本模块迁移到 Azure 机器学习。In this article, you learned how to migrate Execute R Script modules to Azure Machine Learning.

请参阅工作室(经典)迁移系列中的其他文章:See the other articles in the Studio (classic) migration series:

  1. 迁移概述Migration overview.
  2. 迁移数据集Migrate dataset.
  3. 重新生成工作室(经典)训练管道Rebuild a Studio (classic) training pipeline.
  4. 重新生成工作室(经典)Web 服务Rebuild a Studio (classic) web service.
  5. 将 Azure 机器学习 Web 服务与客户端应用集成Integrate an Azure Machine Learning web service with client apps.
  6. 迁移“执行 R 脚本”模块。Migrate Execute R Script modules.