Open topic with navigation

TIBCO GridServer® 7.1.0

# R Interoperability

Before you create an R Service, you must decide which types of clients you intend to support. There are restrictions to the input and return types depending on the client that is used.

There are three main issues to address for each client type:

| • | Input and return value types

| • | `ServiceType` definition

| • | `init` method interface

## Input/return Values and the functionInterface Setting

The `functionInterface` setting in the Service Type determines the conversion scheme that is applied to incoming input arguments and the outgoing return value.

There are three possible settings:

| • | `RAW` (default) - Input arguments and return values are not converted at all.

| • | `UNWRAP_RETURN` - Input arguments are not converted at all. However, if an R function returns a vector with a single element, the single element in the vector is returned instead. This is convenient for Java and .NET Drivers and a requirement for C++ Drivers. This setting has no effect if the returned value has more than one value.

| • | `NATIVE_R` - Input arguments and return values are native R types. Therefore they are not subject to any conversion.

Below are examples of how to create R Services depending on the client that has access to it.

## Supporting C++ Clients

The C++ client is the most restrictive client to support.

## Input and return type

C++ clients only support strings as input arguments and return values. Therefore, if your Service is accessed by a C++ client, all R functions exposed in the Service must only take strings and return a single string value.

## ServiceType

Set `functionInterface` to `UNWRAP_RETURN` for C++ clients.

## init method

If your Service has an init method, it must take at least one argument. For example:

    init <- function(unused) {

    }

The init method requires at least one argument even when `ServiceFactory::createService(const std::string &serviceName)` is used.

The init method can have multiple string arguments and the precise number of parameters must be provided as `initData` when creating a Service. Otherwise, Service initialization fails.

## Supporting Java/.NET Clients

Java and .NET clients are less restrictive than the C++ client.

## Input and return type

Java and .NET clients support their respective native types, and these types can be used as input arguments and return values.

## ServiceType

`functionInterface` can be unset, or set to `UNWRAP_RETURN` depending your preference.

## init method

The init method can have multiple arguments and the precise number of parameters must be provided as `initData` when creating a Service. Otherwise, Service initialization fails.

## Supporting R Clients in R mode

R clients can access Services exposed using the C++ like Service interface and Services implemented in R and exposed as `NATIVE_R`.

R clients can call Services with the C++ like interface and Services exposed as `NATIVE_R` concurrently. Keep in mind that you cannot expose some functions with the C++ like interface and others as `NATIVE_R` in the same Service Type.

## Input and return type

R clients can use native R types as arguments and return values. Refer to the list of supported types below.

## ServiceType

`functionInterface` can be set to `NATIVE_R`.

## init method

The `init` method can have multiple arguments and the precise number of parameters must be provided as `initData` when creating a Service. Otherwise, Service initialization fails.

## Supported R Types

Supported R types are:

| • | `logical`

| • | `integer`

| • | `real`

| • | `raw`

| • | `complex`

| • | `nil` (`NULL` value)

| • | `string`

| • | `vector`

`vector` can contain any combination of the above types and `vector` itself.

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO GridServer®

Copyright © 2001-2022. TIBCO Software Inc. All Rights Reserved.