This article aims to show you one possible way of using SAP Cloud Platform virtual machines to install an R server and connect it to your SAP HANA database system. Please have in mind that this particular reference scenario might not be applicable to every use case.
You already have a dedicated SAP HANA database system in your SAP Cloud Platform account.
SAP HANA supports processing of R code. R is an open-source programming language and software environment for statistical computing and graphics. R server is a TCP/IP server, which allows other programs to use facilities of R from various languages without the need to initialize R or link against R library.
You can install an R server on a virtual machine and connect it to the SAP HANA system running in your account.
Note: The scenario described in this article is for testing and evaluation purposes only. It is done with a root user (superuser) account, which should not be used for productive purposes.
For productive scenarios, follow the official R Installation and Administration documentation. In addition to the packages listed in the guide, install the following ones as well:
1. Create a virtual machine and then connect to it as a root user using an SSH client of your choice. For more information, see Managing Virtual Machines.
2. Add SLES12 repositories:
zypper addrepo -f http://download.opensuse.org/repositories/devel:/languages:/R:/patched/SLE_12/devel:languages:R:patched.repo zypper addrepo -f https://slesrepo.hana.ondemand.com/repo/SUSE/Products/SLE-SERVER/12/x86_64/product/ SUSE12 zypper addrepo -f https://slesrepo.hana.ondemand.com/repo/SUSE/Products/SLE-SDK/12/x86_64/product/ SUSE12SDK
You can list all added repositories by executing the zypper repos command.
3. Install dependencies:
zypper install xorg-x11-devel gcc-fortran readline-devel gcc-c++ libzip-devel libbz2-devel xz-devel pcre-devel libcurl-devel
A couple of popup windows may appear at this step. If you are offered a solution to a downgrade issue in dependencies, choose it. If you are notified that there are package signing keys or a new repository, choose to trust them.
4. Install the R server:
zypper install r-patched
5. Download the necessary R server packages. Choose their latest version at https://cran.r-project.org/src/contrib/.
wget http://cran.rstudio.com/src/contrib/Rserve_1.7-3.tar.gz wget https://cran.r-project.org/src/contrib/kernlab_0.9-25.tar.gz
6. Install these R server packages:
6.1 Launch R and install the R server packages:
install.packages("/root/Rserve_1.7-3.tar.gz", repos = NULL)
6.2 Test if the installation is successful. It should not return any output:
6.3 Quit R:
7. Install the Kernlab package:
7.1 Launch R and install the Kernlab package:
install.packages("/root/kernlab_0.9-25.tar.gz", repos = NULL)
7.2 Test if the installation is successful. It should not return any output:
7.3 Quit R:
8. Create the /etc/Rserv.conf file and add only the following line:
9. Configure the communication between the SAP HANA database system and the virtual machine:
To allow the connection, add a security group rule to the virtual machine using the following console client command:
neo create-security-rule --account mysubaccount --host hana.ondemand.com --user myuser --name myvm --source-id mysystemID --source-type HANA --from-port 6432 --to-port 6432
The source-id field should contain the database ID. Depending on the case, both port fields may contain the same value (for example, 6432).
10. Start the R server:
Note: The port on which you start the R server should be allowed for communication.
R CMD Rserve --RS-port 6432 --no-save --RS-encoding utf8
Check if the process is running using the following command:
ps aux | grep R
The resulting output should be as follows:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 4169 0.0 0.6 99872 27100 ? Ss May11 0:03 /usr/lib64/R/bin/Rserve --RS-port 6432 --no-save --RS-encoding utf8
11. Configure the SAP HANA database system.
11.1 In the cockpit, navigate to SAP HANA / SAP ASE → Database Systems and create a Database User for your user.
11.2 Add the CREATE R SCRIPT system privilege in the HANA database system.
Note: You may already have this system privilege. If you do not have permissions to add it, request these permissions by reporting an incident with component BC-NEO-PERS.
11.3 Connect to the SAP HANA database system via Eclipse IDE and go to the Administration console.
Right-click the database ID, then choose Configuration and Monitoring, and Open Administration.
In the Configuration tab, add the IP and the port (in this case, 6432) of the virtual machine with Rserver in indexserver.ini → right-click calcEngine → Add Parameter → Next → type cer_rserve_addresses in the Key field, the IP and the port in the Value field → Finish:
You can find the IP of the virtual machine in the output of the list-vms command.
12. Test the connection between the SAP HANA database system and the R Server installed on the virtual machine:
12.1 Right-click the database ID in the SAP HANA studio and open the SQL Console view. Then, execute the following SQL statements:
create type RSERVEINFO AS TABLE ( "R.version.platform" NVARCHAR (256), "R.version.arch" NVARCHAR (256), "R.version.os" NVARCHAR (256), "R.version.system" NVARCHAR (256), "R.version.status" NVARCHAR (256), "R.version.major" NVARCHAR (256), "R.version.minor" NVARCHAR (256), "R.version.year" NVARCHAR (256), "R.version.month" NVARCHAR (256), "R.version.day" NVARCHAR (256), "R.version.svn.rev" NVARCHAR (256), "R.version.language" NVARCHAR (256), "R.version.version.string" NVARCHAR (256), "R.version.nickname" NVARCHAR (256)); drop procedure testR; create procedure testR (OUT rinfo RSERVEINFO) LANGUAGE R READS SQL DATA AS BEGIN si <- sessionInfo() si_df <- as.data.frame (si) rinfo <- si_df END; call testR(?);
12.2 After executing the R procedure, the log from the R server call should look something like this:
Statement 'call testR(?)' successfully executed in 75 ms 870 µs (server processing time: 37 ms 348 µs) Fetched 1 row(s) in 0 ms 16 µs (server processing time: 0 ms 0 µs)
The scenario ends here and we hope that it will be helpful to you. Please do not hesitate to share your feedback with us!