I am currently working with KNIME version 4.5.2 (yes, i know…)
I want to reuse one Path Variable many times -actually not in loop but it could be- so I don’t need to configure a writer every time with a different variable names.
I can edit with a ‘Java Edit Variable (simple)’ node, and with this node you can optionally overwrite a variable. But it only works with integer, double and string types. ‘Variable Expressions’ node only works on these three types as well.
The only way I can think of is using Merge variables to pull in the replacement path from a “new” branch. It is important that the branch containing the new variable is never connected to the existing flow as it will then generate a #1 version Overwrite Path Variable.knwf (19.8 KB)
[edit: Of course if your new file name needs to use information from your existing flow, then this isn’t going to work because the moment the “Set File2 Name” node in the sample flow is connected to the existing flow, (ie if it receives flow variables from the main flow) the whole idea breaks. So not necessarily very useful! ]
I’ve checked the workflow and I can see that you already put some mind into this topic. It’s great to learn, but initially I can’t use this idea as I am not typing the variables (are generated from df names) and currently it is all connected.
I’m gonna give it a try connecting all in a different way, and I’ll let you know.
@gonhaddock I wonder if it might be possible to write information you want to have into a table and then read it back and convert the result to a Flow Variable. So once the information in the file has been changed the result from the Flow Variable would also change. I have not thought that thru and it is not pretty - but maybe you can provide us with a sample workflow that would demonstrate where you would like to change the Flow Variable.
Thanks for the second time in the day. I definitely will add +1 to the variable filter development. I could currently configure individually the writers (this was my initial thought) because they are tens, no hundreds. The variables are generated from R snippet DF names. But laziness push me to study all the options.
Good luck @gonhaddock. I uploaded the demo workflow to the hub adding some extra comments.
If you do get a chance to try the component, be sure to let me know if you discover any issues. I’ll probably start using it myself now as I’ve lost count of the number of times I’ve done String Manipulation (Variable) followed by String to Path (Variable) , thinking wouldn’t it be good if…
To add to the already mentioned valuable information, have you considered the replacePath() option?
I used it in a column expression (variable expression has the same functionality I believe) for a case whereby I had a directory with folders based on numbers only. With some associated information, I reconstructed the Path with the replacePath() to create new folders.
For example: replacePath(column("Path"),join(replace(column("path_to_str"),column("combined string") ,""),column("PARTNO"),"_",column("SERIALNUMBER"),"\\",column("FILENAME")))
This is a good piece of information. replacePath + type Path type Variable Expressions would be indeed good reasons for the upgrade. For the time being Column Expressions in 4.5.2 manages a good bunch of format types as well. Then the problem would resides in ‘String to Path (Variable)’ node.
However I will upgrade the version once I finish this workflow, just in case.
Upgrading this Java Edit Variable (simple) to Return Path type would solve the whole workaround. Could you check in version 6 if this is already implemented? Otherwise this is a good feature to recommend for Feedback and Ideas.
First of all thanks to all of you for the constructive brainstorm. I finally came up with a solution using KNIME base nodes. This would be more similar to my use case; then it can be implemented in a continuous workflow or in a loop. I’m sharing my concept as requested by @mlauber71
I’ve tested @takbb component and I think that it’s good for most use cases. Good insights from it as well. That’s why I’m marking it as a recommended solution. At the end the variable has to be typed somewhere (in my case I coded in the R Snippet nodes) and these pop up dialogue boxes are very friendly.
All these workarounds could be avoided with the implementation of an ‘Overwrite Variable’ function within the ‘String to Path (Variable)’ node.
The forced persistence of flow variables in the main workflow has never made any sense to me. Why can’t we just treat flow variables the same as columns. We should be able to easily rename / filter out / overwrite flow variables in the exact same way as columns. It would open up a lot more options for users and cut down on clutter.