## MDX / R Integration

Integrating R with icCube is a project in its starting blocks. This integration is based on the Renjin project (thanks Alexander Bertram). The idea is starting to investigate several possibilities mainly on data-mining, predictive analysis and advanced calculations.

If you've an interest or want to collaborate on this direction do not hesitate to contact icCube ( support @ iccube . com ) and/or Renjin project directly.

### Configuration

By default R support is turned off. It can be activated via the user defined property _ r.active _ in the file icCube.xml.

### Usage

The notation *R!method( ... ) * allows for accessing any R methods from an MDX statement.
Note that the conversion of the parameters (as well as the result) is handled automatically by the
MDX engine. The following calculated member is computing the natural logarithm of a measure :
of PI using JAVA classes:

WITH MEMBER [Measures].[val] AS R!log( [Measures].[Amount] )

R constants can be used accessed the same way. E.g., the following calculated measure is defined as TRUE:

WITH MEMBER [Measures].[val] AS R!is.na( R -> NA )

Note that the sequence operator (e.g., from:to) is not yet supported when passing parameters to R functions. As a workaround, the function seq(from,to) which is equivalent can be used.

### Examples

#### Random values

We can also use R to generate a random vector of normal distributed values. Pay attention, we use the const flag to ensure the vector of random values is the same for each request.

WITH /* creates the vector of n normal distributed values */ CONST FUNCTION randomVector() as R!rnorm(500, mean=0.5, sd=0.25) /* quick check that is the same 'random' vector at request level */ MEMBER [var 0.5%] as R!quantile(randomVector(), 0.05 ) MEMBER [median (Java)] as randomVector()->median() MEMBER [median (R) ] as R!quantile(randomVector(), 0.5 ) /* an example to calculate the histogram, us p so the sum is 1.0 */ MEMBER [p-(,0)] as randomVector()->phist(NULL,0) MEMBER [p-(0,0.25)] as randomVector()->phist(0,0.25) MEMBER [p-(0.25,0.5)] as randomVector()->phist(0.25,0.5) MEMBER [p-(0.5,0.75)] as randomVector()->phist(0.5,0.75) MEMBER [p-(0.75,1.00)] as randomVector()->phist(0.75,1.0) MEMBER [p-(1.0,)] as randomVector()->phist(1,NULL) SELECT [Measures].allmembers - [Measures].members on 0 FROM [MyCube]

### Installation

To install Renjin you have to download the standalone Java library jar file from here (the latest version we tested was 0.8.2357). Once downloaded, copy the jar file to icCube plugin directory: ${ic3-data}/plugins/.

### Configuration

#### Activation

The R / MDX integration can be (de)activated using the property *r.active*
within the file *$install/bin/icCube.xml*.

#### Packages

No specific configuration is required to access R methods from the default base packages.
Within the *$install/bin/icCube.xml* file the *userDefinedProperties*
*r.rLibs* and *r.initScript* allows for configuring the access to other
R packages.

#### Multithreading

R integration is currently not multithreaded (contact us if it's needed). Only one and only one R function will be evaluated at a given point in time.

### Support

Renjin is not part of icCube, and icCube does not make any guarantee other than on the integration code. For a production integration please test carefully.

### License

The integration is based in Renjin that is licenced under a GPLv2 license. This license has some limitations mainly when integrating into a product (wikipedia), check the compatibility with your solution before starting the integration.