sp_execute_external_script R 脚本“无法启动 png() 设备" [英] sp_execute_external_script R script 'unable to start png() device'
问题描述
我正在尝试使用 sp_execute_external_script 命令在 SQL Server R 中创建绘图,但无法创建绘图 png 图像:
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,状态 20,第 13 行发生R"脚本错误在使用 HRESULT 执行sp_execute_external_script"期间0x80004004.消息 39019,级别 16,状态 2,第 13 行 外部脚本发生错误:png(file = reportfile) 中的错误:无法启动png() 设备调用:source -> withVisible -> eval -> eval -> png In另外:警告消息:1:在 png(file = reportfile) 中:无法打开文件 'C:\temp\Covid19-Weekly.png' 用于写入 2:在 png(file =reportfile) : 打开设备失败
Msg 39004, Level 16, State 20, Line 13 A 'R' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004. Msg 39019, Level 16, State 2, Line 13 An external script error occurred: Error in png(file = reportfile) : unable to start png() device Calls: source -> withVisible -> eval -> eval -> png In addition: Warning messages: 1: In png(file = reportfile) : unable to open file 'C:\temp\Covid19-Weekly.png' for writing 2: In png(file = reportfile) : opening device failed
执行错误.检查输出以获取更多信息.错误eval(ei, envir) : 执行错误.检查输出以获取更多信息信息.调用:runScriptFile -> source -> withVisible -> eval ->eval -> .Call 执行停止
Error in execution. Check the output for more information. Error in eval(ei, envir) : Error in execution. Check the output for more information. Calls: runScriptFile -> source -> withVisible -> eval -> eval -> .Call Execution halted
它也以管理员身份失败.请帮忙.
It also fails as an administrator. Please help.
推荐答案
READ &c:\temp 的写入权限为所有应用程序包".
READ & WRITE permissions for c:\temp to "ALL APPLICATION PACKAGES".
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()'
这篇关于sp_execute_external_script R 脚本“无法启动 png() 设备"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!