运行R脚本时,azure函数中的Powershell错误

时间:2018-06-11 15:47:00

标签: r powershell azure azure-functions

我目前正在将R微服务部署到azure函数,但我遇到了一些问题。 我从azure站点扩展中安装了R可执行文件,并使用PowerShell运行带有此R可执行文件的R脚本。

该脚本完全运行,但是我遇到了一些似乎不是来自我的R脚本的奇怪错误,但却是特定的PowerShell错误。 以下是我得到的日志:

2018-06-11T15:37:14.373 [Info] PowerShell Timer trigger function executed at:06/11/2018 15:37:14

2018-06-11T15:37:17.924 [Info] [1] "Retrieving data"

2018-06-11T15:37:18.158 [Error] D:\home\R-3.3.3\bin\x64\Rscript.exe : Loading required package: methods

at run.ps1: line 4

+ D:\home\R-3.3.3\bin\x64\Rscript.exe

+ ___________________________________

    + CategoryInfo          : NotSpecified: (Loading required package: methods:String) [], RemoteException

    + FullyQualifiedErrorId : NativeCommandError


at run.ps1: line 4

+ D:\home\R-3.3.3\bin\x64\Rscript.exe

+ ___________________________________

    + CategoryInfo          : NotSpecified: (:) [], RemoteException

    + FullyQualifiedErrorId : NativeCommandErrorMessage


at run.ps1: line 4

+ D:\home\R-3.3.3\bin\x64\Rscript.exe

+ ___________________________________

    + CategoryInfo          : NotSpecified: (:) [], RemoteException

    + FullyQualifiedErrorId : NativeCommandErrorMessage

2018-06-11T15:37:20.837 [Info] [1] "Finished retrieving data, computing first function"

2018-06-11T15:37:21.040 [Info] [1] "2nd function.."

2018-06-11T15:37:21.040 [Info] [1] "3rd function.."

2018-06-11T15:37:21.061 [Info] [1] "last function.."

2018-06-11T15:37:21.061 [Info] [1] "Finished everything"


at run.ps1: line 4

+ D:\home\R-3.3.3\bin\x64\Rscript.exe

+ ___________________________________

    + CategoryInfo          : NotSpecified: (:) [], RemoteException

    + FullyQualifiedErrorId : NativeCommandErrorMessage

2018-06-11T15:37:21.290 [Error] Exception while executing function: Functions.TimerTriggerEngagement. Microsoft.Azure.WebJobs.Script: PowerShell script error. Loading required package: methods.

2018-06-11T15:37:21.337 [Error] Function completed (Failure, Id=..., Duration=7114ms)

我的PowerShell脚本运行简单:

cd D:\home\site\wwwroot\microservices
D:\home\R-3.3.3\bin\x64\Rscript.exe engagement.r

例如,当我在RStudio中运行我的脚本时,我没有警告/错误。 有线索吗?对这些错误的解释是什么?

编辑(答案)

正如ahmelsayed指出的那样,这是天蓝色的powershell的奇怪行为。通过运行一些测试,代码就像

一样简单
library('httr')
library('parsedate')
library('jsonlite')
print('Testing the azure functions')

for (i in 1:10){
    print(i)
}

返回

2018-06-18T09:43:08.204 [Error] D:\home\R-3.3.3\bin\x64\Rscript.exe : Loading required package: methods

at run.ps1: line 4

+ D:\home\R-3.3.3\bin\x64\Rscript.exe

+ ___________________________________

    + CategoryInfo          : NotSpecified: (Loading required package: methods:String) [], RemoteException

    + FullyQualifiedErrorId : NativeCommandError

2018-06-18T09:43:09.003 [Info] [1] "Testing the azure functions"

2018-06-18T09:43:09.048 [Info] [1] 1

2018-06-18T09:43:09.048 [Info] [1] 2

2018-06-18T09:43:09.048 [Info] [1] 3

2018-06-18T09:43:09.048 [Info] [1] 4

2018-06-18T09:43:09.048 [Info] [1] 5

2018-06-18T09:43:09.048 [Info] [1] 6

2018-06-18T09:43:09.048 [Info] [1] 7

2018-06-18T09:43:09.048 [Info] [1] 8

2018-06-18T09:43:09.081 [Info] [1] 9

2018-06-18T09:43:09.081 [Info] [1] 10

2018-06-18T09:43:09.173 [Error] Exception while executing function: Functions.TimerTriggerTest. Microsoft.Azure.WebJobs.Script: PowerShell script error. Loading required package: methods.

2018-06-18T09:43:09.220 [Error] Function completed (Failure, Id=..., Duration=5223ms)

似乎只是在R中加载一些软件包并运行简单代码会在Powershell中生成错误,即使所有软件包都已正确加载并且代码运行正常。

1 个答案:

答案 0 :(得分:0)

我认为这只是来自powershell的奇怪行为,取决于它正在使用的io主机。看到这个问题和接受的答案Error when calling 3rd party executable from Powershell when using an IDE