2017-06-20 52 views
1

我正在通过一些关于使用SQL和R的教程工作。但是当我试图运行R脚本以获取'ggplot'库时,我收到以下错误SQL 2016与R - 错误HRESULT 0x80004004

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年,2017年SSMS,MS R打开3.4.0 有R的集成与Visual Studio 2015年运作良好,并没有错误。可以下载库软件包并运行脚本而不会出错。只有当我开始使用SMSS时,我无法下载软件包

回答

0

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

修复方法是将软件包安装在单独的全局可读目录(例如c:\Rlib)中。完成之后,在library()调用之前添加.libPaths("c:\\Rlib"),将脚本指向该位置。

+0

喜香,非常感谢。这是一个许可问题。 R的默认安装位于SQL目录内,因此写入权限被禁用 – Stevieb143

1

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

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

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

入住这里: Install additional R packages on SQL Server

相关问题