sqlrutils package

The sqlrutils package provides a mechanism for R users to put their R scripts into a T-SQL stored procedure, register that stored procedure with a database, and run the stored procedure from an R development environment.

Package details Description
Current version: 1.0.0
Built on: R 3.4.3
Package distribution: SQL Server 2017 Machine Learning Services (Windows only) and SQL Server 2016 R Services
R Client (Windows and Linux)

How to use sqlrutils

The sqlrutils library is installed as part of SQL Server Machine Learning when you add R to your installation. You get the full collection of proprietary packages plus an R distribution with its base packages and interpreters. You can use any R IDE to write R script calling functions in sqlrutils, but the script must run on a computer having SQL Server Machine Learning with R.

The workflow for using this package includes the following steps:

  • Define stored procedure parameters (inputs, outputs, or both)
  • Generate and register the stored procedure
  • Execute the stored procedure

In an R session, load sqlrutils from the command line by typing library(sqlrutils).


You can load this library on computer that does not have SQL Server (for example, on an R Client instance) if you change the compute context to SQL Server and execute the code in that compute context.

Function list

Class Description
executeStoredProcedure Execute a SQL stored procedure.
getInputParameters Get a list of input parameters to the stored procedure.
InputData Input data for the stored procedure.
InputParameter Input parameters for the stored procedure.
OutputData Output from the stored procedure.
OutputParameter Output parameters from the stored procedure.
registerStoredProcedure Register the stored procedure with a database.
setInputDataQuery Assign a query to an input data parameter of the stored procedure.
setInputParameterValue Assign a value to the an input parameter of the stored procedure.
StoredProcedure A stored procedure object.

Next steps

Add R packages to your computer by running setup for R Server or R Client:

Next, review the steps in a typical sqlrutils workflow:

See also

Package Reference
R tutorials for SQL Server