forked from microsoft/sql-server-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enabling R scripts to run and Installing required R Packages.sql
69 lines (54 loc) · 2.83 KB
/
Enabling R scripts to run and Installing required R Packages.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--Enabling sp_execute_external_script to run R scripts in SQL Server 2016 and installing package in order to run the Script TelcoChurn-Main.sql and TelcoChurn-Operationalize.sql sucessfully.
--SP_EXECUTE_EXTERNAL_SCRIPT is a stored procedure that execute provided script as argument on external script to a provided language (in this case R language). To enable normal function of this external stored procedure, you must have administrator access to your SQL Server instance in order to run sp_configure command (and set following configuration):
EXECUTE sp_configure;
GO
--To enable execution of external script add an argument:
EXECUTE sp_configure 'external scripts enabled', 1;
GO
--And after that run the reconfiguration as:
RECONFIGURE;
GO
--InstallPackage using sp_execute_external_script
EXECUTE sp_execute_external_script
@language = N'R'
,@script=N'install.packages("ggplot")'
WITH RESULT SETS (( ResultSet VARCHAR(50)));
-- using Download.file command
EXECUTE sp_execute_external_script
@language = N'R'
,@script=N'download.file("https://cran.r-project.org/bin/windows/contrib/3.4/ggplot2_2.1.0.zip","ggplot")
install.packages("ggplot", repos = NULL, type = "source")'
WITH RESULT SETS (( ResultSet VARCHAR(50)));
--InstallPackage using sp_execute_external_script
EXECUTE sp_execute_external_script
@language = N'R'
,@script=N'install.packages("gplots")'
WITH RESULT SETS (( ResultSet VARCHAR(50)));
-- using Download.file command
EXECUTE sp_execute_external_script
@language = N'R'
,@script=N'download.file("https://cran.r-project.org/bin/windows/contrib/3.4/gplots_3.0.1.zip","gplots")
install.packages("gplots", repos = NULL, type = "source")'
WITH RESULT SETS (( ResultSet VARCHAR(50)));
--InstallPackage using sp_execute_external_script
EXECUTE sp_execute_external_script
@language = N'R'
,@script=N'install.packages("xgboost")'
WITH RESULT SETS (( ResultSet VARCHAR(50)));
-- using Download.file command
EXECUTE sp_execute_external_script
@language = N'R'
,@script=N'download.file("https://cran.r-project.org/bin/windows/contrib/3.4/xgboost_0.4-4.zip","xgboost")
install.packages("xgboost", repos = NULL, type = "source")'
WITH RESULT SETS (( ResultSet VARCHAR(50)));
--InstallPackage using sp_execute_external_script
EXECUTE sp_execute_external_script
@language = N'R'
,@script=N'install.packages("qcc")'
WITH RESULT SETS (( ResultSet VARCHAR(50)));
-- using Download.file command
EXECUTE sp_execute_external_script
@language = N'R'
,@script=N'download.file("https://cran.r-project.org/bin/windows/contrib/3.4/qcc_2.6.zip","qcc")
install.packages("qcc", repos = NULL, type = "source")'
WITH RESULT SETS (( ResultSet VARCHAR(50)));