Qlik Community

QlikView Documents

Documents for QlikView related information.

Announcements
Leverage your QlikView investment to modernize BI – see how! Join Group

QV with R macro coding made easy !

Not applicable

QV with R macro coding made easy !

Hi,

Thanks to @etk (Integrating QV with R example kit.zip ) for showing us the integration of QV with R.

As well to Brian Bauer for helping out with the integration problems of integration with various version of R.

I have recently been using this integration, and have found out an easy way of using the macro, without writing same lines of R code in the macro with 'R.EvaluateNoReturn' and the inverted commas.

Please go through the images attached below.

  1. Just write the R code in a '.R' script file.
  2. Save the file as a '.R' file
  3. Test the file from the R application itself.(You can find on the web as how to run a stored R script. Its very simple!)
  4. Then in the QlikView Macro. Just need to write 4 to 5 lines of code to get it done.

Qlikview.PNG.png

Qlikview Zoomed in.PNG.png

Note:

  1. Please test the R code  in R first and if it executes successfully then integrate
  2. You will need to write the exporting from QV path before this procedure in the Macro.

I guess some might be knowing this already.

But I hope it might help someone so felt it worth sharing

Thanks,

Regards,

Swapneel

Comments
Not applicable

Hi Swapneel,
I am new to QlikView.
the code i have written in my .r file works in R but the macro doesnot qwork.
I didnot get the note -  2.You will need to write the exporting from QV path before this procedure in the Macro.
Please explain

0 Likes
Not applicable

Hi Rohan,

Firstly Yes, you will need to write the exporting from QV path before calling the R function as a part of the Macro.

And then call the R function (.R) file.

Please see the below attached image.

Hope it helps, feel free to contact

Thanks & Regards,

Swapneel

R_made_Easy.png

0 Likes
Not applicable

Hi swapneel,
thanks for the Image.I am now able to run the code in QlikView
It was very helpful...:)

Not applicable

I am happy to hear that it worked & it made your work easy indeed.

And you are most welcome

Regards

Swapneel

0 Likes
Not applicable

Heyy...Do u know how to get multidimensional array data back to QlikView
I tried using getsymbol().
It doesnot work.

Regards,
Rohan Shetty

0 Likes
Not applicable

I was able to make the connection happen for the demo, and now I am trying to write a macro in QlikView with some of our data. I am having trouble though for some reason exporting the data from QlikView to run the analysis on. Below is my current macro... any ideas? Would really appreciate the help (my internship is coming to a quick close!)

AC

Function CurrentPath()

   

     Set v = ActiveDocument.GetVariable("vAppPath")

    CurrentPath = Replace(v.GetContent.String,"\","/")

End Function       

Sub Exporting

     Set myTable=ActiveDocument.GetSheetObject("DataToR")

     myTable.Export CurrentPath&"/ExportFile.csv",",",0

End Sub

Sub RunR

     Set R = CreateObject("StatConnectorSrv.StatConnector")

     R.Init "R"

     R.EvaluateNoReturn "setwd('CurrentPath')"

     R.EvaluateNoReturn "source('QlikViewScript.R')"

     R.close

    ActiveDocument.DoReload 2,false,false

End Sub

0 Likes
Not applicable

Hi Alice,

I guess there's an error at the line

          R.EvaluateNoReturn "setwd('CurrentPath')"

you are trying to call CurrentPath variable in R, which actually exists in QV.

So I guess thats the point of error.

Change or remove that line for a while & try testing  it.

Do let me know how this goes.

Regards.

Swapneel

0 Likes
Not applicable

I tried removing the line but it still seems to not be working. I don't think the data actually gets exported to R, otherwise I would see my CPU increase for R studio. Does the object have to be a particular type to export? Like a straight table?

0 Likes
Not applicable

I'm sorry that above comment is incorrect. The table is being created, because it shows up in my files. I think the issue is that R is not able to read the table. Do you know why this is happening? If I try to read the data into R, I get the following error:

When run this code and try to view the table: testData<-read.csv("O:/QlikView Training/Alice/ExportFile.csv", encoding='UTF-8')

Error I get in the table viewer:

/content?title=testData&file=a2fbce58927548b6a7173da062f36c84.htm not found

I read somewhere else that all objects sent from Qlikview are encoded "UTF-8" (Maybe the persons statement was incorrect). Could this be the issue?

0 Likes
Not applicable

Hi Alice,

Plz tell me if you are running the same macro, where is the data being exported ?

The path of csv where its exported, needs to be set in the set path & then the call to the R script needs to be initiated.

About the formatting, I dont think it should make any difference as it has been the same always or try making changes to the Document Properties and set the encoding to ANSI

ANSI.PNG.png

Regards

Swapneel

0 Likes
Version history
Revision #:
1 of 1
Last update:
‎2014-05-09 12:32 AM
Updated by: