qlik-oss / sse-r-plugin

A Qlik server-side extension plugin for accessing R.
MIT License
67 stars 71 forks source link

QlikSense-R %in% filtering not working #11

Closed SilviuAndries closed 7 years ago

SilviuAndries commented 7 years ago

Hello all,

I am stuck for a lot of time in a R-QlikSense issue and I would really appreciate your help.

Summary:

I am using R code into a QlikSense expression and I need to filter my table based on a CharType field "Country" using %in% function or "==".

This is working directly in RStudion locally, in RStudio on QlikSense Server but not working in QlikSense expression. Also, this filter works fine even in QlikSense expression but when applied on numeric field.

QlikSense code:

sum( R.ScriptEval(

' library(ChainLadder) library(data.table)

test_table <- data.table(Country=q$Country, Upside_volume=q$Upside_volume, Synergies=q$Synergies);

#test_table <- test_table[ test_table$Country %in% "AT" , ]  # <--- Not Working!
  test_table <- test_table[ test_table$Synergies %in% "2" , ]   # <--- Working!

final_value <- sum(test_table$Upside_volume);
print(final_value)

' , Country as Country
, Upside_volume as Upside_volume , Synergies as Synergies ))

I have tried multiple options, to convert directly in R script the Country field into char or vector , but without success.

It seems that it is an issue with the QlikSense - R connector which is not working properly for Characters filtering...

Thanks a lot in advance, Silviu

tobiaslindulf commented 7 years ago

Hi, It sounds like you are trying to pass data fields from Qlik of different data types. Country is a string I guess in your case. I do not know about Synergies if that is a numeric or a string. The ScriptEval method assume that all data fields that are passed from Qlik are numerics. You are trying to pass both numeric and strings in the different parameters. I think what you are looking for is this: https://github.com/qlik-oss/sse-r-plugin/blob/master/GetStarted.md#example-expression-3 In your case you should exchange the first two rows: R.ScriptEval( '

with

R.ScriptEvalEx('SNN', '

or R.ScriptEvalEx('SNS', ' if Synergies is a string.

Try that out and see what happens.