Welcome to R machine learning client for SAP HANA (hana.ml.r) !

This library enables R data scientists to access SAP HANA data and build machine learning models using the data directly in SAP HANA.


R machine learning client for SAP HANA provides a set of client-side R functions for accessing and querying SAP HANA data, and a set of functions for developing machine learning models.

R machine learning client for SAP HANA consists of two main parts:

  • A set of machine learning APIs for different algorithms in SAP HANA Predictive Analysis Library (PAL).

  • SAP HANA DataFrame, which provides a set of methods for analyzing data in SAP HANA without bringing the data to the client.

This R hana.ml.r library uses JDBC/ODBC to access SAP HANA.

Getting Started

Install hana.ml.r, please refer to Installation page for obtaining the hana.ml.r tar.gz file:

install.packages("path to hana.ml.r-XXX.tar.gz", repos=NULL, type="source")

Quick Start

First, please set up a JDBC/ODBC connection to SAP HANA:

conn.jdbc <- hanaml.ConnectionContext(dsn = <host>:<port>,
                                      username = 'xxxx',
                                      password = 'xxxx',
                                      odbc = FALSE,
                                      jdbcDriverPath = <path to jdbcDriver>,


conn.odbc <- hanaml.ConnectionContext(dsn = <ODBC data source name>,
                                      username = 'xxxx',
                                      password = 'xxxx',
                                      odbc = TRUE,

For SAP HANA port number, please refer to the following rules:

  • For HANA tenant databases, use the port number 3NN13 (where NN is the SAP instance number - e.g. 30013).
  • For HANA system databases in a multitenant system, the port number is 3NN13.
  • For HANA single-tenant databases, the port number is 3NN15.

Returns a DataFrame referenced to a SAP HANA table:

df <- conn$table(table='MY_TABLE', schema='MY_SCHEMA')

Convert to a R data.frame:

r.df <- df$Collect()

Convert to a HANA DataFrame from a R data.frame:

df <- ConvertToHANADataFrame(conn,
                             data = r.df,
                             table = 'temp_tbl',
                             force = TRUE,
                             native = FALSE,
                             col.types = list(ds = "DATE"))

An example to call hanaml.UnifiedClassification function:

uc.dt <- hanaml.UnifiedClassification(func = 'DecisionTree',
                                      data = df,
                                      partition.method = 'user.defined',
                                      purpose = "PURPOSE",
                                      algorithm = 'c45',
                                      model.format = 'json',
                                      min.records.of.parent = 2,
                                      min.records.of.leaf = 1,
                                      priors = list("Play" = 0.5,
                                                    "Do not Play" = 0.5),
                                      thread.ratio = 0.4,
                                      resampling.method = 'cv',
                                      evaluation.metric = 'auc',
                                      fold.num = 5,
                                      progress.indicator.id = 'CV',
                                      param.search.strategy = 'grid',
                                      parameter.values = list(split.threshold = c(1e-3 , 1e-4, 1e-5)))

Call the predict function:

predict(uc.dt, data = predict.df, key='ID', verbose=False)


R machine learning client for SAP HANA is provided via the SAP Developer License Agreement

By using this software, you agree that the following text is incorporated into the terms of the Developer Agreement:

If you are an existing SAP customer for On Premise software, your use of this current software is also covered by the terms of your software license agreement with SAP, including the Use Rights, the current version of which can be found at SAP Software Use Rights