Common Issues with R Services Packages

By:   |   Updated: 2017-03-29   |   Comments (2)   |   Related: > SQL Server 2016


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.


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



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.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips


Article Last Updated: 2017-03-29

Comments For This Article




Wednesday, September 4, 2019 - 3:37:17 PM - Vitor Montalvão Back To Top (82245)

Hi Marta,

I never faced that error but from the error message it seems that you're trying to use packages built in R 3.6.1 and running them in a R version older that R 3.5.0. If it's that the case, upgrade your R version to a at least R 3.5.0.

It can also be the other way around, i.e., you're loading an old version of the package in a newer R version. If that's the case then try to see if there's any tidyverse package that is compatible with your current R version.

Hope that I could help.

Regards,

Vitor


Wednesday, September 4, 2019 - 1:08:18 PM - Marta Marinhas Back To Top (82243)

I'm trying to install the package tidyverse and the error I get is 'cannot read workspace version 3 written by R 3.6.1; need R 3.5.0 or newer'.

Do you have a solution for this?

Thank you,

Marta















get free sql tips
agree to terms