R Services in SQL Server 2016
R Services is an add-on to a SQL Server 2016 database engine instance, used for executing R code and functions on SQL Server. Code runs in an extensibility framework, isolated from core engine processes, but fully available to relational data as stored procedures, as T-SQL script containing R statements, or as R code containing T-SQL.
R Services includes a base distribution of R, overlaid with enterprise R packages from Microsoft so that you can load and process large amounts of data on multiple cores and aggregate the results into a single consolidated output. Microsoft's R functions and algorithms are engineered for both scale and utility: delivering predictive analytics, statistical modeling, data visualizations, and leading-edge machine learning algorithms in a commercial server product engineered and supported by Microsoft.
R libraries include RevoScaleR, MicrosoftML (R), and others. Because R Services is integrated with the database engine, you can keep analytics close to the data and eliminate the costs and security risks associated with data movement.
R Services was renamed in SQL Server 2017 to SQL Server Machine Learning Services, reflecting the addition of Python.
SQL Server 2016 is R only. The following table describes the features in SQL Server 2016.
|SQL Server Launchpad service||A service that manages communications between the external R runtimes and the SQL Server instance.|
|R packages||RevoScaleR is the primary library for scalable R. Functions in this library are among the most widely used. Data transformations and manipulation, statistical summarization, visualization, and many forms of modeling and analyses are found in these libraries. Additionally, functions in these libraries automatically distribute workloads across available cores for parallel processing, with the ability to work on chunks of data that are coordinated and managed by the calculation engine.
MicrosoftML (R) adds machine learning algorithms to create custom models for text analysis, image analysis, and sentiment analysis.
sqlRUtils provides helper functions for putting R scripts into a T-SQL stored procedure, registering a stored procedure with a database, and running the stored procedure from an R development environment.
olapR is for specifying MDX queries in R.
|Microsoft R Open (MRO)||MRO is Microsoft's open-source distribution of R. The package and interpreter are included. Always use the version of MRO installed by Setup.|
|R tools||R console windows and command prompts are standard tools in an R distribution.|
|R Samples and scripts||Open-source R and RevoScaleR packages include built-in data sets so that you can create and run script using pre-installed data|
|Pre-trained models in R||Pre-trained models are created for specific use cases and maintained by the data science engineering team at Microsoft. You can use the pre-trained models as-is to score positive-negative sentiment in text, or detect features in images, using new data inputs that you provide. The models run in R Services, but cannot be installed through SQL Server Setup. For more information, see Install pre-trained machine learning models on SQL Server.|
Using R Services
Developers and analysts often have code running on top of a local SQL Server instance. By adding Machine Learning Services and enabling external script execution, you gain the ability to run R code in SQL Server modalities: wrapping script in stored procedures, storing models in a SQL Server table, or combining T-SQL and R functions in queries.
The most common approach for in-database analytics is to use sp_execute_external_script, passing R script as an input parameter.
Classic client-server interactions are another approach. From any client workstation that has an IDE, you can install Microsoft R Client, and then write code that pushes execution (referred to as a remote compute context) to data and operations to a remote SQL Server.
Finally, if you are using a standalone server and the Developer edition, you can build solutions on a client workstation using the same libraries and interpreters, and then deploy production code on SQL Server Machine Learning Services (In-Database).
How to get started
Start with setup, attach the binaries to your favorite development tool, and write your first script.
Step 1: Install and configure the software.
Step 2: Gain hands-on experience using either one of these tutorials:
Step 3: Add your favorite R packages and use them together with packages provided by Microsoft