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 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 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:
R 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:
R 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 with the corresponding command and add only the following line:
9. Start the R server:
Note: The port on which you start the R server should be allowed for communication. For that to happen, the port should be configured using the security group rule commands.
R CMD Rserve --RS-port XXXX --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 XXXXX --no-save --RS-encoding utf8
10. Configure SAP HANA.
10.1 In the cockpit, navigate to Persistence → Database Systems and create a Database User for your user.
10.2 Add the CREATE R SCRIPT system privilege.
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.
10.3 Connect to SAP HANA 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 of the virtual machine with Rserver in indexserver.ini → calcEngine → cer_rserve_addresses.
You can find the IP of the virtual machine in the output of the list-vms command.
11. Configure the communication between SAP HANA 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 myaccount --host hana.ondemand.com --user myuser --name myvm --source-id mysystemID --source-type HANA --from-port XXXX --to-port YYYY
The source-id field should contain the database ID. Depending on the case, both port fields may contain the same value.
12. Test the connection between SAP HANA and the R Server installed on the virtual machine:
12.1 Execute the following SQL statements (in the SQL Console) in the SAP HANA studio:
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 DIVIDE_SPAMDATA()' successfully executed in 1.292 seconds (server processing time: 1.256 seconds) - Rows Affected: 4601
The scenario ends here and we hope that it will be helpful to you. Please do not hesitate to share your feedback with us!