Search

Advertisements

SQL Server 2016 - Getting started with R Services

R Services (In-Database) provides a platform for developing and deploying intelligent applications that uncover new insights.

R Services (In-Database) integrates the R language with SQL Server, you can keep analytics close to the data and eliminate the costs and security risks associated with data movement.

To install R Services



Click on SQL Server set up file and follow below steps:




To use R code in T-SQL:

Execute below commands from SSMS and then restart both SQL Server Launchpad & SQL Server services

Exec sp_configure  'external scripts enabled', 1 
Reconfigure  with override
   




--------------------------------------------------------------------------------------------------------

After successfully setting up R-Services, let us try tutorial from MSDN BOL



Open Windows PowerShell command console and run below commands to download data & scripts:

Set-ExecutionPolicy Unrestricted -Scope Process -Force

Change the destination directory if required:

$source = 'https://raw.githubusercontent.com/Azure/Azure-MachineLearning-DataScience/master/Misc/RSQL/Download_Scripts_R_Walkthrough.ps1' 
$ps1_dest = "$pwd\Download_Scripts_R_Walkthrough.ps1" 
$wc = New-Object System.Net.WebClient 
$wc.DownloadFile($source, $ps1_dest) 
.\Download_Scripts_R_Walkthrough.ps1 –DestDir
'C:\tempR'



Run below command from Windows PowerShell command console to execute downloaded scripts [create database, tables, stored procedure, function and import data]

.\RunSQL_R_Walkthrough.ps1



Open RGui and Install R libraries by running below commands

# Install required R libraries for this walkthrough if they are not installed.  

if (!('ggmap' %in% rownames(installed.packages()))){ 
  install.packages('ggmap') 

if (!('mapproj' %in% rownames(installed.packages()))){ 
  install.packages('mapproj') 

if (!('ROCR' %in% rownames(installed.packages()))){ 
  install.packages('ROCR') 

if (!('RODBC' %in% rownames(installed.packages()))){ 
  install.packages('RODBC') 
}
 



install.packages("ggmap", lib=grep("Program Files", .libPaths(), value=TRUE)[1]) 
install.packages("mapproj", lib=grep("Program Files", .libPaths(), value=TRUE)[1])
install.packages("ROCR", lib=grep("Program Files", .libPaths(), value=TRUE)[1])
install.packages("RODBC", lib=grep("Program Files", .libPaths(), value=TRUE)[1])




Other lessons that are part of this tutorial can be continued from here.

References:


No comments:

Advertisements