Installing R packages with rxInstallPackages in Microsoft R Server

In MicrosoftML package comes – in my opinion – long anticipated function for installing R packages for SQL Server and Microsoft R Server. And, I am super happy.

Last year, in one of my previous blog posts, I have been showing how to install R package from SSMS using sp_execute_external_script. Now, with new package MicrosoftML (that is part of Microsoft R Server 9.x and above)  new function is available that enables you to easy install the package and also little bit more.

Code is relatively simple and straightforward:


EXECUTE sp_execute_external_script
 @language = N'R'
 ,@script = N'

 packagesToInstall <- c("caret","tree","party")
 SqlServerCC <- RxInSqlServer(connectionString = "Driver=SQL Server;
 rxInstallPackages(pkgs = packagesToInstall, owner = '', 
+scope = "shared", computeContext = "SqlServerCC");';

This is way too easy to be true, but it is. Make sure to do couple of things prior to running this code:

  1. set the compute environment to where your packages are installed
  2. set up the correct permissions and access
  3. Check up also the tcp/ip protocols

In rxInstallPackages function use computeContext parameter to set either to “Local” or to your  “SqlServer” environment, you can also use scope as shared or private (difference is, if you install package as shared it can be used by different users across different databases, respectively for private). You can also specify owner if you are running this command out of db_owner role.

Happy SQLR-ing!


4 thoughts on “Installing R packages with rxInstallPackages in Microsoft R Server

  1. Hi Tomaž,

    Do you know, if the package installation works from a rtvs session ? I’m trying hard with no luck so far.
    : Verifying permissions to install packages on SQL server…
    Error in rxInstallPackagesSql(computeContext = computeContext, pkgs = pkgs, :
    Permission denied for installing packages on SQL server for owner=”, scope=’shared’.

    I tried also your approach but the account which execute the the script (SQL Server LaunchPad I guess) is blocked by the proxy and it fails on package download.

    For me this feature is some how broken, or at least not well documented.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s