Common Issues with R Services Packages
By: Vitor Montalvao | Updated: 2017-03-29 | Comments (2) | Related: More > SQL Server 2016
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.
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:
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:
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:
When trying to run R code with R Services the following error will thrown "there is no package called..." as shown below:
This error is because the package has not really been installed as the following image shows:
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:
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:
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:
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:
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:
This can be seen when searching for the package:
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:
- Please keep these errors in mind as you work with R Services.
- Check out the other tips on R Services.
Last Updated: 2017-03-29
About the author
View all my tips