Unable to communicate with the runtime for 'R' script in SQL Server
By: Vitor Montalvao | Updated: 2016-11-11 | Comments (6) | Related: More > SQL Server 2016
When trying to run R scripts in SQL Server a runtime error for 'R' script was raised. You get the following error "Unable to communicate with the runtime for "R" script. Please check the requirements of 'R' runtime". This is shown in the below screenshot. What does this mean and how do you fix this?
The error message might make you think it is a permission issue, but if you are familiar with 'R' you might know that 'R' doesn't like spaces in the folder path and this is what we are going to investigate.
This issue is related to the working directory for the R Services and if you are facing this error, the first thing to do is check the path for the working directory for R Services. If you didn't change the default file locations during the R Services installation then there is a good chance that the R Services working directory path has folder names with spaces and it's necessary to change the working directory to a path with no spaces.
Changing R Services Working Directory
To change the working directory, edit the rlauncher.config file that can be found in C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Binn (default location).
If your disk is formatted to accept old 8.3 format file names you can just set the working directory with this format:
Alternatively you can change the working directory to a path that doesn't have spaces in the folder names and save the file. If you do this you will need to copy the full subfolder structure and grant necessary permissions for the R accounts (see next section).
Moving R Services Subfolder and Files (only if working directory moved)
This step only needs to be done if you changed the working directory location.
I used robocopy to copy the entire folder structure. I used the (/E) to get all folders and files and the (/SEC) to keep the respective folder permissions.
robocopy C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\ExtensibilityData C:\R\ExtensibilityData /E /SEC
Note that target folder should already be created and the correct permissions set for the MSSQLLaunchpad service account.
Check all subfolders to make sure the correct permissions have been set for the MSSQLLaunchpad service account and respective MSSQLSERVERnn account.
Restart SQL Server Launchpad Service
Restart the MSSQLLaunchpad service.
You should now be able to run the 'R' script without any more issues.
When I wrote this tip there was not much information in Microsoft's documentation about the issue with spaces in folder names for R Services. Fortunately this is somewhat well known with people that work with 'R', so with a little research and troubleshooting I was able to get this working. Hopefully this tip can help someone in the future that faces this issue and has no clue how to solve it.
- More R tips
Last Updated: 2016-11-11
About the author
View all my tips