Accessing Flow Variables in Python (and R) Snippet

Hi,

How could one access the flow variables in Python Snippet module?  

 

I'm using Knime 2.5.2  (on Win7 64bit), with:

- KNIME Ptyhon Scripting extension 1.1.0.201112121427

- KNIME Python Scripting 2.5.0.0031109

The plugin is running off of local python (2.7.2) installation.

 

Thank you in advance.

 

P.S.,

I also couldn't figure out how to access flow variable in R Snippet module.  Is there a way in R as well?  Thanks!

Hi,

for the Python scripting extension and the R scripting extension (from the community contributions) you can access flowvariable with this placeholder:

FLOWVAR(myFlowVariableName)

If it contains a string, the statement has to be surrounded by quotes.

Let me know if it works.

But be aware: This is not the case for nodes from KNIME Python Scripting 2.5.0.0031109

Thank you very much!  It works very well with Python (flow variable is named abc):

import sys
sys.stderr.write("*******************************************flowvartest1\n")
sys.stderr.write("%r"%FLOWVAR(abc))
pyOut = kIn     # both are assumed to be dictionaries

 

I wasn't so successful in using Rsnippet (community version), so I will stick to the default R Snippet:

R<-sum(R[1:2]+$${Iabc}$$)

Thanks for your feedback. Can you write down the code you tried in R?

Yes, I've tried the following code just to see if it works in the community version of R:

# throws: ERROR	 R Snippet	 Execute failed: voidEval failed, request status: error code: 127

x <- FLOWVAR(abc)
rOut <- rIn

 

In the default R snippet, here is what was used:

#would not write to KNIME console
write("***************test2",stdout())
write("***************test2",stderr())

R<-sum(R[1:2]+$${Iabc}$$)

 

The input table was

col1 col2
123 456

 

And flow variable was

int abc = 345

generated by TableCreator-->TableRowToVariable nodes

much too late of course, but the correct script for the R snippet should be:

x <- FLOWVAR(abc)
rOut <- kIn

the table which is sent to R is named "kIn"! this should solve the problem.