繁体   English   中英

sp_execute_external_script R 脚本'无法启动 png() 设备'

[英]sp_execute_external_script R script 'unable to start png() device'

I am trying to create a plot in SQL Server R using the sp_execute_external_script command, but it fails to create the plot png image:

DECLARE @stateName nvarchar(50) = 'Michigan'
EXEC sp_execute_external_script
 @language = N'R',
 @script = N'
    covidWeeklyDataSet <- InputDataSet
    # set up report file for chart
    reportfile <- "C:\\temp\\Covid19-Weekly.png"
    png(file = reportfile)
    plot(x = covidWeeklyDataSet[, 1], y = covidWeeklyDataSet[, 2],
        main = paste(state_name, "Weekly Covid 19 Counts", sep = ""),
        col = 3, ylab = "Cases", xlab = "Dates", ylim = c(0, 35000))
    par(new = TRUE)
    plot(x = covidWeeklyDataSet[, 1], y = covidWeeklyDataSet[, 3],
         col = 2, ylab = "Cases", xlab = "Dates", ylim = c(0, 35000))
    dev.off()
 ',
 @input_data_1 = N'SELECT [date], cases, deaths FROM #weekly',
 @params = N'@state_name nvarchar(20)',
 @state_name = @stateName

错误信息如下:

消息 39004,级别 16,State 20,第 13 行 执行“sp_execute_external_script”期间发生“R”脚本错误,HRESULT 为 0x80004004。 消息 39019,级别 16,State 2,第 13 行发生外部脚本错误:png 错误(文件 = 报告文件):无法启动 png() 设备调用:源 -> withVisible -> eval -> eval -> png 另外:警告消息:1:在 png 中(文件 = 报告文件):无法打开文件 'C:\temp\Covid19-Weekly.png' 进行写入 2:在 png 中(文件 = 报告文件):打开设备失败

执行错误。 查看 output 了解更多信息。 eval 中的错误(ei,envir):执行错误。 查看 output 了解更多信息。 调用:runScriptFile -> source -> withVisible -> eval -> eval ->.Call 执行停止

作为管理员,它也失败了。 请帮忙。

c:\temp 对“所有应用程序包”的读写权限。

EXEC sp_execute_external_script
 @language = N'R',
 @script = N'
#file.create("c:\\temp\\mytest.png")
png(filename = "c:\\temp\\mytest.png",
    width = 500, height = 500, units = "px", pointsize = 12,
    bg = "white",  res = NA)
x <- sample(c("A","B","C","D"), 20, replace=TRUE)
plot(table(x))
dev.off()'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM