| author | VanMSFT |
|---|---|
| ms.author | vanto |
| ms.date | 02/18/2021 |
| ms.service | sql |
| ms.subservice | machine-learning-services |
| ms.custom | linux-related-content |
| ms.topic | include |
::: zone pivot="platform-linux-ubuntu"
Note
If you have installed R in the default location of /usr/lib/R, you can skip this section and move on to the Install Rcpp package section. ::: zone-end
First, edit the mssql-launchpadd service to add the R_HOME environment variable to the file /etc/systemd/system/mssql-launchpadd.service.d/override.conf
-
Open the file with systemctl
sudo systemctl edit mssql-launchpadd
-
Insert the following text in the
/etc/systemd/system/mssql-launchpadd.service.d/override.conffile that opens. Set value of R_HOME to the custom R installation path.[Service] Environment="R_HOME=<path to R>" -
Save and close.
Next, make sure libR.so can be loaded.
-
Create a custom-r.conf file in /etc/ld.so.conf.d.
sudo vi /etc/ld.so.conf.d/custom-r.conf
-
In the file that opens, add path to libR.so from the custom R installation.
<path to the R lib> -
Save the new file and close the editor.
-
Run
ldconfigand verify libR.so can be loaded by running the following command and checking that all dependent libraries can be found.sudo ldconfig ldd <path to the R lib>/libR.so
Set the datadirectories option in the extensibility section of /var/opt/mssql/mssql.conf file to the custom R installation.
sudo /opt/mssql/bin/mssql-conf set extensibility.datadirectories <path to R>Run the following command to restart mssql-launchpadd.
sudo systemctl restart mssql-launchpaddFollow these steps to install the Rcpp package.
-
Start R from a shell:
sudo ${R_HOME}/bin/R -
Run the following script to install the Rcpp package in the ${R_HOME}\library folder.
install.packages("Rcpp", lib = "${R_HOME}/library");Follow these steps to download and register the R language extension, which is used for the R custom runtime.
-
Download the R-lang-extension-linux-release.zip file from the SQL Server Language Extensions GitHub repo.
Alternatively, you can use the debug version (R-lang-extension-linux-debug.zip) in a development or test environment. The debug version provides verbose logging information to investigate any errors, and is not recommended for production environments.
-
Use the MSSQL extension for Visual Studio Code to connect to your SQL Server instance and run the following T-SQL command to register the R language extension with CREATE EXTERNAL LANGUAGE.
Modify the path in this statement to reflect the location of the downloaded language extension zip file (R-lang-extension-linux-release.zip).
CREATE EXTERNAL LANGUAGE [myR] FROM (CONTENT = N'/path/to/R-lang-extension-linux-release.zip', FILE_NAME = 'libRExtension.so.1.1'); GO
Execute the statement for each database you want to use the R language extension in.
[!NOTE] R is a reserved word and can't be used as the name for a new external language name. Use a different name instead. For example, the statement above uses myR.