r - SQL 2016 与 R - 错误 HRESULT 0x80004004

标签 r sql-server-2016 microsoft-r

我正在学习一些有关使用 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 时,我无法下载软件包

最佳答案

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

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

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

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

关于r - SQL 2016 与 R - 错误 HRESULT 0x80004004,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44655141/

相关文章:

识别 R 中的日期时间格式

r - 根据 R 中的值进行动态子集化

r - 如何创建特定月份和/或日期序列 "n"次

java - 在 Centos 6.5 上的 Rstudio 服务器上加载 rJava 时出错

r - 将所有内核与 Microsoft R Open 和 Google Compute Engine 结合使用

r - 使用 dplyr 跨列求和 NA

sql - 计算两个值之间的百分比

sql-server - 在sql server中将 “&lt;”和 “&gt;”和 "&lt;\"替换为 “<” ,“>”和</

sql - 允许登录运行存储过程而无法从表中选择

readLines 与同时使用 Azure Data Lakes 和 R Server 时等效