cancel
Showing results for 
Search instead for 
Did you mean: 

how to create a Custom R Component in Expert Analytics

Former Member
0 Kudos

hello experts,

I want to write Custom R Component in SAP PAL to make some calculate, but the codes below cannot work successfully, always existed some problems. I wondern, how to convert my R script to fitted by Expert Analytics.

There are 2 dimensions in PAL, which consisted of some decimals. I set the column 1 to "a" and column2 to "b".

The R script as below:

test <- function(a,b) {

result <- a[3]+b[4];

return(result);

};

but with error: non-numeric argument to binary operator

Accepted Solutions (0)

Answers (1)

Answers (1)

achab
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi, did you already review our tutorials and Tech. Doc (from help.sap.com/pa)?

as a side-note you need to set a R server as a side-car to SAP HANA, it's not done as part of PAL.

thanks and regards

antoine

Former Member
0 Kudos

Hi,

I have set the R Server already and used to work successfully in HANA studio with the R script. Now I try to create it in PAL. But as  I known, the R script must be converted to the R format which could be identified by Expert Analytics.

I didn’t sure about the conversion from R script to R format in PAL.

In the R script, it is just a additive operation of two elements from column_1 and column_2. According to SAP document about Expert Analytics, I declare the variables firstly in the function and then make the calculation. But it didn’t work.

I tried many times with the R script but always with error: non-numeric argument to binary operator.

I wonder, if there is grammatical error existed ??

AndreasForster
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Yic,

I turned your R function into the format needed for Expert Mode.

test <- function(mydata, ColName1, ColName2) {

  result <- mydata[, ColName1] + mydata[, ColName2] ;

  return(list(out=result))

};

The dataframe needs to be passed into the function as parameter. Also, the names of the columns you want to add up have to be passed as Strings. The output is passed as an element in a list.

More examples and a Tutorial are listed here

Usually it is best to test the R function first in your R Editor. Then I personally prefer to implement it in Expert mode connecting to some local source (ie flat file). Only if that is working, I would try to use this with the R server next to HANA.

Many Greetings

Andreas

Former Member
0 Kudos

Hello Andreas,

Thanks for your R function. I tried it in my Expert Analytics. There is an error existed: error in file(con "rb" ) cannot open the connection.

stack trace:

3. file(con, "rb")

2. readBin("tempPA.png", what="raw",n=1e+06)

1. paste(readBIn("tempPA.png", what="raw",n=1e+06),collapse="")


I have already made PAL connected with HANA, thus the columns could be loaded dirctly from HANA.

I don't understand, why it still "cannot open the connection"?

AndreasForster
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Yic,

Does the code when when connecting to non-HANA, ie flat file?

This would give confidence in the R code that is used for the extension.

However, you issue could also be with the HANA / R integration. Can you execute the sample given in here (calling R directly from HANA Studio)?

http://help.sap.com/hana/SAP_HANA_R_Integration_Guide_en.pdf

Many Greetings

Andreas