This project is advanced function integration into Yellowfin’s report development interface so that R scripts can be called on.

Download Yellowfin-R jar
Download Yellowfin-R-interface-010816.jar and copy to
[YF installation directory]/appserver/webapps/ROOT/WEB-INF/lib
Download and Install R
Download latest version of R from here and install.

Note : For this library version, R should be installed on the same server as of Yellowfin server

Install Rserve
Rserve 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 to the R library.
To install Rserve from R-console use the following command.
        install.packages(“Rserve”)
Start Rserve
In order to utilize the R scripts, Rserve should be running. In the R console, enter the following commands to start Rserve.
        library(Rserve)
Rserve()

Note : On Linux you can also start Rserve from command like using
        R CMD Rserve
Define RSCRIPT_PATH for R-Scripts
All R-Scripts must recide in a directory which must have read and write permissions to the users.
Set Environmental variable RSCRIPT_PATH which points to the directory where R scripts are stored.
        RSCRIPT_PATH=/home/foo/Rscritps
Writing R-Scripts
For Yellowfin to understand and execute R Script, a slightly different structure will be used in the R-script as discussed below.
Consider a sample script called <R_file_name>.R. The input parameters passed from yellowfin will be available in a file called <R_file_name.R>.input.csv.

Post processing, the R-script should write the results (only one column) back to <R_file_name.R>.result.csv

Note:- Your R-Scripts must reside inside the RSCRIPT_PATH directory

Below is a sample R-Script for Neural Networks. Copy this script and make sure it runs without any errors in R. (You may need to install the required libraries).

Data set for this can be downloaded from here.

Sample R-Script : neural-net-script.R

###################################################
rPATH    <- Sys.getenv(“RSCRIPT_PATH“)
# Input filename will be <r-scriptname>.input.csv
rINPUT   <- paste0(rPATH,”/neural-net-script.R.input.csv“)
# Output filename will be <r-scriptname>.result.csv
rOUTPUT  <- paste0(rPATH,”/< R_file_name >.result.csv“)
###################################################

library(magrittr)
building <- TRUE
scoring  <- ! building
crv$seed <- 42
dataset  <- read.csv(file=rINPUT, header=FALSE, sep=”,”)
set.seed(crv$seed)
crs$nobs <- nrow(dataset)
crs$sample <- crs$train <- sample(nrow(dataset), 0.7*crs$nobs)
crs$validate <- sample(setdiff(seq_len(nrow(dataset)), crs$train), 0.15*crs$nobs)
crs$test <- setdiff(setdiff(seq_len(nrow(dataset)), crs$train), crs$validate)
#V1 : MinTemp                        #V2 : MaxTemp
#V3 : Rainfall                            #V4 : Evaporation
#V5 : RainToday                        #V6 : RainTomorrow (Target Variable)
crs$input <- c(“V1”, “V2”, “V3”, “V4″,”V5”)
crs$target  <- “V6″
library(nnet, quietly=TRUE)
set.seed(199)
crs$nnet <- nnet(as.factor(V6) ~ .,data=dataset[crs$sample,c(crs$input, crs$target)],size=10, skip=TRUE, MaxNWts=10000, trace=FALSE, maxit=100)
crs$pr <- predict(crs$nnet, newdata=dataset, type=”class”)
# After all the processing is complete, write back to a file
write.table(crs$pr, file=rOUTPUT, row.names=FALSE, col.names = FALSE)

Calling R-Script from Yellowfin
To apply an advanced function first you will need to ensure the field you wish to apply to have been added to your table. Often, when applying functions,

you may need two copies of the field in your table; one to display the original values and the second to have a function applied to it.
To apply a function to a field in your table from the Data-step of the report builder, complete the following:

  1. Open the field’s drop down menu, in either of these locations:
    1. 1aThrough the Columns/Rows list
    2. Or Through the Table Preview1b
  2. Now select the Advanced Function option from the list, opening the Advanced Function display.2
  1. You will now need to complete the function options:
    1. Select R Serve from Select Functions3
    2. Select Name of the function you want to apply i.e. Apply R-Script
    3. Provide the filename (without path) of the R-Script to execute.
    4. Select all the required parameters as per the requirement.
  2. When defined, click Save to apply the function. This will execute the R script in R and return the results back to the selected column.

Screen Shot After applying Advance Functionsc

Download more sample R-scripts from here

R can also be installed on a different server than Yellowfin Server. Please contactinfo@aptusdatalabs.com for further details.