Like what you see? Have a play with our trial version.

Error rendering macro 'rw-search'

null

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

We have included an example of a custom advanced function, which enables the use of R within a report. 

Installing Rserve R

Expand
titleClick to expand...

Yellowfin can integrate R scripts into the report builder through the use of Advanced Functions.

  1. Download Yellowfin-R jar and copy into Yellowfin/appserver/webapps/ROOT/WEB-INF/lib
  2. Download and install R
  3. Install Rserve - Rserve is a TCP/IP server which allows other programs to use facilities of R from various languages without the need to initialise R or link to the R library. Use the following command:
    install.packages("Rserve")
    install.packages("magrittr")
    install.packages("rattle") (linux requires special installation)
  4. Start Rserve - for Yellowfin to connect to R, Rserve should be running. In the R console, enter the following commands:
    library(Rserve)
    Rserve()
  5. Define RSCRIPT_PATH for R-Scripts - all R-Scripts must reside in a directory with read and write permissions for users. Set the environmental variable RSCRIPT_PATH to point to this directory. Example:
    RSCRIPT_PATH=/home/foo/Rscripts

 

Writing R-Scripts

Expand
titleClick to expand...

For Yellowfin to understand and execute R script a slightly different structure will be used in the script 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 . 

Below is a sample R-Script for Neural Networks. Copy this script and make sure it runs without any errors in R.

Code Block
languagec#
titleSample R-Script : neural-net-script.R
setwd("C:/R/R-3.2.3/bin/x64")
library(rattle)   # To access the weather dataset and utility commands. 
library(magrittr) # For the %>% and %<>% operators. 
building <- TRUE 
scoring  <- ! building 
# A pre-defined value is used to reset the random seed so that results are repeatable. 
crv$seed <- 42  
# Load the data. 
rPATH  <- Sys.getenv("RSCRIPT_PATH") 
rINPUT <- paste0(rPATH ,"/neural-net-script.r.input.csv") 
rOUTPUT <- paste0(rPATH ,"/neural-net-script.r.result.csv") 
dataset <- read.csv(file=rINPUT, header=FALSE, sep=",") 
# Note the user selections.  
# Build the training/validate/test datasets. 
set.seed(crv$seed)  
crs$nobs <- nrow(dataset) # 366 observations  
crs$sample <- crs$train <- sample(nrow(dataset), 0.7*crs$nobs) # 256 observations 
crs$validate <- sample(setdiff(seq_len(nrow(dataset)), crs$train), 0.15*crs$nobs) # 54 observations 
crs$test <- setdiff(setdiff(seq_len(nrow(dataset)), crs$train), crs$validate) # 56 observations 
# The following variable selections have been noted. 
crs$input <- c("V1", "V2", "V3", "V4","V5") 
crs$target  <- "V6" 
#============================================================ 
# Neural Network  
#============================================================ 
 
# Build a neural network model using the nnet package. 
library(nnet, quietly=TRUE) 
# Build the NNet model. 
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) 
#============================================================ 
# Score a dataset.  
#============================================================ 
# Obtain probability scores for the Neural Net model on weather.csv [validate]. 
#crs$pr <- predict(crs$nnet, newdata=dataset[crs$validate, c(crs$input)], type="class") 
#crs$pr <- predict(crs$nnet, newdata=dataset[crs$validate, c(crs$input)], type="class") 
crs$pr <- predict(crs$nnet, newdata=dataset, type="class") 
write.table(crs$pr, file=rOUTPUT, row.names=FALSE, col.names = FALSE) 


...