Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server 2017 (14.x) only
This article explains how to install new R packages on an instance of SQL Server where machine learning is enabled. There are multiple approaches to choose from. Using T-SQL works best for server administrators who are unfamiliar with R.
The CREATE EXTERNAL LIBRARY statement makes it possible to add a package or set of packages to an instance or a specific database without running R or Python code directly. However, this method requires package preparation and additional database permissions.
All packages must be available as a local zipped file, rather than downloaded on demand from the internet.
All dependencies must be identified by name and version, and included in the zip file. The statement fails if required packages are not available, including downstream package dependencies.
You must be db_owner or have CREATE EXTERNAL LIBRARY permission in a database role. For details, see CREATE EXTERNAL LIBRARY.
If you are installing a single package, download the package in zipped format.
It's more common to install multiple packages due to package dependencies. When a package requires other packages, you must verify that all of them are accessible to each other during installation. We recommend creating a local repository using miniCRAN to assemble a full collection of packages, as well as igraph for analyzing packages dependencies. Installing the wrong version of a package or omitting a package dependency can cause a CREATE EXTERNAL LIBRARY statement to fail.
Copy the zipped file containing all packages to a local folder on the server. If you do not have access to the file system on the server, you can also pass a complete package as a variable, using a binary format. For more information, see CREATE EXTERNAL LIBRARY.
Open a Query window, using an account with administrative privileges.
Run the T-SQL statement CREATE EXTERNAL LIBRARY
to upload the zipped package collection to the database.
For example, the following statement names as the package source a miniCRAN repository containing the randomForest package, together with its dependencies.
CREATE EXTERNAL LIBRARY [randomForest]
FROM (CONTENT = 'C:\Temp\Rpackages\randomForest_4.6-12.zip')
WITH (LANGUAGE = 'R');
You cannot use an arbitrary name; the external library name must have the same name that you expect to use when loading or calling the package.
If the library is successfully created, you can run the package in SQL Server, by calling it inside a stored procedure.
EXEC sp_execute_external_script
@language =N'R',
@script=N'library(randomForest)'
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Certification
Microsoft Certified: Azure Database Administrator Associate - Certifications
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.