Skip to content

Latest commit

 

History

History
114 lines (76 loc) · 3.78 KB

File metadata and controls

114 lines (76 loc) · 3.78 KB
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

Custom installation of R

::: 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

Update the environment variables

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

  1. Open the file with systemctl

    sudo systemctl edit mssql-launchpadd
  2. Insert the following text in the /etc/systemd/system/mssql-launchpadd.service.d/override.conf file that opens. Set value of R_HOME to the custom R installation path.

    [Service]
    Environment="R_HOME=<path to R>"
    
  3. Save and close.

Next, make sure libR.so can be loaded.

  1. Create a custom-r.conf file in /etc/ld.so.conf.d.

    sudo vi /etc/ld.so.conf.d/custom-r.conf
  2. In the file that opens, add path to libR.so from the custom R installation.

    <path to the R lib>
    
  3. Save the new file and close the editor.

  4. Run ldconfig and 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

Grant access to the custom R installation folder

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>

Restart mssql-launchpadd service

Run the following command to restart mssql-launchpadd.

sudo systemctl restart mssql-launchpadd

Install Rcpp package

Follow these steps to install the Rcpp package.

  1. Start R from a shell:

    sudo ${R_HOME}/bin/R
  2. Run the following script to install the Rcpp package in the ${R_HOME}\library folder.

install.packages("Rcpp", lib = "${R_HOME}/library");

Register language extension

Follow these steps to download and register the R language extension, which is used for the R custom runtime.

  1. 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.

  2. 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.