Learn more about SQL Server tools

mssqltips logo
giveaway
 

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Whitepapers          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories

 

Common Issues with R Services Packages


By:   |   Read Comments   |   Related Tips: More > SQL Server 2016

Attend a SQL Server Conference for FREE >> click to learn more


Problem

R is a collection of libraries and being open source, the number of available libraries grows every day. R Services is delivered with a base package of libraries with the ability to add more as you need. In this tip, I will show the more common errors that can occur when managing packages in R Services.

Solution

In this tip we will address the following scenarios:

  • Error - "lib is not writable"
  • There is no Package Called...
  • Compilation Failed for Package Error
  • LoadLibrary Failure
  • Uninstall Errors

lib is not writable Error with R Services

Do not use SQL Server to install R packages. It will return a "lib is not writable" error like the one provided below:

Error library folder is not writable

In fact the library folder is really set to be read-only and even if you try to change it, it will be set back immediately to read-only again. So the solution is to use R.exe to install a package. You can find R.exe in the R Services folder (default path is C:\Program Files\Microsoft SQL Server\MSSQL13.<instance_name>\R_SERVICES\bin\R.exe). Then run the command to install the required package as it should work now:

Install Package in R Services

There is no Package Called... Error in R Services

The install.packages function allows us to install packages to a user library.  However, R Services only allows us to use the default library.  When installing into another library SQL Server will not to be able to run the package functions.

As shown in the following image, when installing a package and providing another library location, R will not complain about it:

jsonlite install in different path

When trying to run R code with R Services the following error will thrown "there is no package called..." as shown below:

Error no package called

This error is because the package has not really been installed as the following image shows:

No package found

To solve this issue, install the package by providing the default library location: C:\Program Files\Microsoft SQL Server\MSSQL13.<instance_name>\R_SERVICES\library or install the package without providing the library location so it will install in the correct location by default.

Compilation Failed for Package Error in R Services

Be sure that you download the Windows version of the package (usually a .zip file). If you download a package for a non-Windows platform it will return a "compilation failed for package" when you try to install it as the following example shows:

Error Compilation Failed

To solve this issue you just need to download and install the correct package version for Windows.

LoadLibrary Failure for R Services

Also be sure that you download the right Windows version of the package that supports by your R version, otherwise it will be installed, but it may not work as the following example shows.

I have downloaded the latest jsonlite package that has been built for R v3.3.2, but I am installing it in a R v3.2.2 version as highlighted in the below image:

Install different package version

Since it looks like the library has installed without errors you can only realize the issue when trying to use the library. In the below image you can see an example of the "LoadLibrary failure" error that can occur:

LoadLibrary failure

As shown in the next image, jsonlite library has been installed, but as stated by the Built column in the image below it is supported for R v3.3.2 and that is why the LoadLibrary failure error occurs:

Compare versions

To solve this issue, remove the wrong package version and install the correct one.

Errors Uninstalling an R Services Package

As for installing a package, also do not use SQL Server to uninstall packages. It will return no error, but the package will not be removed:

Remove Package in SSMS

This can be seen when searching for the package:

Package found

To correctly uninstall a package from R Services library, run the remove.packages("<library_name>",.libPaths()) command in R.

It will not return a message, but you can confirm the package has been removed by running the find.package command:

Remove Package in R
Next Steps
  • Please keep these errors in mind as you work with R Services.
  • Check out the other tips on R Services.


Last Update:


signup button

next tip button



About the author
MSSQLTips author Vitor Montalvao Vitor Montalv„o is a SQL Server engineer with 20 years of experience in SQL Server, specializing in performance & tuning, data modelling, migration and security.

View all my tips
Related Resources





Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Notify for updates 


SQL tips:

*Enter Code refresh code     



Learn more about SQL Server tools