How to access a (special) flow variable in the R-Snippet

Dear all,

I would like to use the currentInteration variable within a R-Script. For "standard" variable it seems to be something like
x <- "FLOWVAR(Name_of_the_variable)"

With currentIteration it does not work in the same manner.

Any hint for me???

Best regards, Jürgen

PS: R-Scripting is a very good approach, but I have not found a way to "get rid off" one file with all templates....(It would be nice to have one file per template)

I'm not sure I follow your problem.  For me the currentIteration flow variable is readilly avaiable within the R-snippet as $${IcurrentIteration}$$ (selectable from the flow variable list on the left hand side in the R-snippet dialog/config box).  This is reffering to the R->Local->R Snippet (Local) node.

 

Are you using the R snippet from the R node collection or from the 'community node' colleciton? 

Paul B

Hi Jürgen,

indeed, the handling of the flow variables in the R Scripting Integration (community contributions) is different from KNIME's R integration (then one Paul was mentioning).

I think you did it already the right way, but be aware that in the case you are mentioning x will be a string! If you what it to be a number (currentIteration is Integer) leave the quotes away.

➤FLOWVAR(name of flow variable) will be replaced by the value of the flow variable
➤Var_string = apple
“FLOWVAR(Var_string)” = “apple”
➤Var_num = 5.5
FLOWVAR(Var_num) = 5.5
“FLOWVAR(Var_num)” = “5.5”

Concerning your "PS:" you can define as many template file as you want in the preferences, enable and disable them. For us it seemed more convinient to have all template in one file. Here is another hint: if you use the category in the header of your template, your templates appear sorted into "folders".

########################################################################################
# name: a nice plot
# author: your name here
# category: folder/subfolder/subsubfolder
# preview: plotpicture.png

Best,

Martin

Thank you very much Martin for your help.

My script example for our community...

#The script should take a set of columns our of a table

min <- FLOWVAR(currentIteration)*5+3;
max <- (FLOWVAR(currentIteration)+1)*5+2;
rOut <- kIn[,min:max];

Best regards, Jürgen

I cannot find any syntax problem but are you sure that your input table contains as many columns as you would like to get back?

I just ran the calculation of min and max with iteration values 1 - 10 and got the following values:

        min max
 [1,]    8   12
 [2,]   13   17
 [3,]   18   22
 [4,]   23   27
 [5,]   28   32
 [6,]   33   37
 [7,]   38   42
 [8,]   43   47
 [9,]   48   52
[10,]   53   57
 

how many columns does you input table have and how many iterations do you want to run? does it fail in the first iteration? could you try to use the openInR node and replace the flow variable with the current value to see whether this succeeds?

Hello,

the script is only a working example ... Sometimes I am missing a small piece of code and therefore I put the script in the forum.

Thank you very much 

Jürgen

PS: R-Scripting is a very good approach, but I have not found a way to "get rid off" one file with all templates....(It would be nice to have one file per template)

 

You could write a script to combine templates from individual files, if you prefer having them separate.  To make it easier to work with the single templates file, I created a couple of small scripts.

One extracts templates by name.  I use this to append an appropriate 'template' to my snippets file when creating a new one.

The other rearranges templates in my file based on a sorted list of template names.