【问题标题】:SQL 2016 with R - Error HRESULT 0x80004004带有 R 的 SQL 2016 - 错误 HRESULT 0x80004004
【发布时间】:2017-06-20 13:57:36
【问题描述】:

我正在阅读一些关于使用 SQL 和 R 的教程。但是当我尝试运行 R 脚本以获取“ggplot”库时,我收到以下错误

Msg 39004, Level 16, State 20, Line 1
A 'R' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 1, Line 1
An external script error occurred: 
Error in library("ggplot2") : there is no package called 'ggplot2'
Calls: source -> withVisible -> eval -> eval -> library

Error in ScaleR.  Check the output for more information.
Error in eval(expr, envir, enclos) : 
Error in ScaleR.  Check the output for more information.
Calls: source -> withVisible -> eval -> eval -> .Call
Execution halted

(0 row(s) affected)

原文是

INSERT INTO chartBinary (binData)
EXEC sp_execute_external_script
@language = N'R',
@script = N'
library("ggplot2");
img <- inputDataSet;
image_file = tempfile();
png(filename = image_file, width=800, height=600);
print(ggplot(img, aes(x = AirportID, y = WindSpeed)) +
labs(x = "Airport ID", y = "Wind Speed") +
theme(axis.text.x = element_text(angle=90, hjust=1, vjust=0)) +
geom_point(stat = "identity") +
geom_smooth(method = "loess", aes(group = 1)) +
geom_text(aes(label = AirportID), size = 3, vjust = 1.0) +
geom_text(aes(label = round(WindSpeed, digits = 2)), size = 3, vjust = 2.0));
dev.off();
OutputDataset <- data.frame(data=readBin(file(image_file,"rb"),what=raw(),n=1e6));',
@input_data_1 = N'SELECT AirportID, AVG(CONVERT(float, WindSpeed)) as   WindSpeed 
FROM
[Weather_Sample] GROUP BY AirportID ORDER BY AirportID;',
@input_data_1_name = N'inputDataSet',
@output_data_1_name = N'OutputDataset';

系统有SQL 2016、SSMS 2017、MS R Open 3.4.0 与 R 的集成适用于 Visual Studio 2015 并且没有错误。可以下载库包并运行没有错误的脚本。只有当我开始使用 SMSS 时,我才无法下载软件包

【问题讨论】:

    标签: r sql-server-2016 microsoft-r


    【解决方案1】:

    您需要将 ggplot2 包安装到 SQL Server 实例。 有多种方法可以将不可用的 R 包安装到 SQL Server 实例。

    您将根据您的设置选择适合您的方法。

    如果您在本地计算机上工作,那么您需要下载软件包的 Windows 二进制文件(zip 文件)并使用 T-SQL 进行安装。

    检查这里: Install additional R packages on SQL Server

    【讨论】:

      【解决方案2】:

      出于安全原因,SQL Server 使用具有较低权限的单独帐户运行您的 R 脚本。特别是,这与您自己的用户帐户不同。因此,如果您将软件包安装在用户目录下,脚本将无法找到它们。

      解决方法是将软件包安装在一个单独的、全局可读的目录中(比如c:\Rlib)。完成此操作后,通过在 library() 调用之前添加 .libPaths("c:\\Rlib") 将您的脚本指向该位置。

      【讨论】:

      • 嗨,洪,非常感谢。这是一个许可问题。 R 的默认安装位于 SQL 目录中,因此禁用了写权限
      【解决方案3】:

      近 2 天以来,我一直在努力寻找解决此错误的方法。我尝试设置权限,结果仍然相同。没有依赖问题。我试图运行外部 C# 代码(我知道 SQLCLR)。

      所以在谷歌搜索并尝试了所有可能的解决方案后,我回到了微软网站,我注意到语言扩展只能从 SQL Server CU3 和更高版本运行。我决定检查我使用的是哪个版本,结果发现我运行的是早期版本。所以我安装了最后一个累积更新,工作完成了,我摆脱了那个错误。

      底线:

      • 检查您是否至少安装了 SQL Server CU3
      • 将“所有应用程序包”的权限设置为 \MSSQL

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 2018-01-15
        • 1970-01-01
        • 1970-01-01
        • 2018-06-07
        • 1970-01-01
        • 2016-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多