Qlik Community

Qlik Server Side Extensions Discussions

Discussion Board for collaboration on Server-Side Extensions and Advanced Analytics Integration.

Highlighted
Partner
Partner

R - Load data from RDS file

Hi everyone,

I'm trying to merge my work in R, with some basic Qlik dashboards. Now my first issue to read a RDS file (R dataframe export) into a table in QlikSense with this loading script :

 

[Feature_importance]:
Load 
	Feature,
	Num(Gain) as Gain,
	Num(Cover) as Couverture,
	Num(Frequency) as Frequence
Extension R.ScriptEval('library(dplyr);
						data <- readRDS("C:/path/feature_importance.RDS");
                        col.types <- sapply(data, class);
                        print(col.types);
                        data[, c("Feature", "Gain", "Cover", "Frequency")];');

 

 

My problem is that every feature is read as a string, but I would like to display and format them as numerics in my dashboard tables. Using Num() in script did not change this.

The printed col.types for my data.frame are :
Feature : Char
Gain : Numeric
Cover : Numeric
Frequency : Numeric

Labels (4)
1 Reply
Partner
Partner

Re: R - Load data from RDS file

Hi Alexbec,

Qlik will receive the data type from R, so since the Feature field is a Char data type, Qlik will use this same type, even its content has numbers.

Well, to avoid that you must transform this column directly on R, recommend to use a Factor data type, cause Qlik will recognize it with a number, even there is a number.

And recommend also ever end your with the data frame display you want to send to Qlik to avoid data transport mistakes.

Follow my code:

 

[Feature_importance]:
Load 
	Feature,
	Num(Gain) as Gain,
	Num(Cover) as Couverture,
	Num(Frequency) as Frequence
Extension R.ScriptEval('library(dplyr);
	data <- readRDS("C:/path/feature_importance.RDS");
        col.types <- sapply(data, class);
        print(col.types);
        data[, c("Feature", "Gain", "Cover", "Frequency")];
        data$Feature = as.factor(data$Feature);
        str(data);
        data;
        ');

 

 

 

Follow my table on Qlik:

clipboard_image_0.png

Follow the RServe display:

clipboard_image_1.png

Good luck,

Pedro