how to create workflow variable of array or list type
Hi,
If you create your variable from a table, you first need to create a collection column, e.g. by using the List aggregation function of the GroupBy node or simply the Create Collection Column node. Then you can use the Table Row to Variable node to create the variable.
Kind regards,
Alexander
Hello @AlexanderFillbrunn,
is it possible to send this workflow variable into an R Snippet node?
Best Regards,
Roland
Hi Roland,
It seems like the R Snippet does not support collection columns. Could you concatenate everything into a string with comma separation and pass that?
Kind regards,
Alex
Hi Alexander,
Thanks for your proposal.
It does not work.
Roland
Hi Roland,
Why does it not work? Could you elaborate? You could use Split Collection Column and then Column Aggregator with Concatenate to create a string. This can then be passed to R and split again using R code.
Kind regards,
Alexander
Hi Alexander,
I tried to do that.
Could you have a look at the attached workflow?
Thanks!
Roland
string variable to r snippet node.knwf (13.2 KB)
Hi Roland,
Please see attached workflow for how I would do it.
Kind regards,
Alexander
string variable to r snippet node.knwf (11.2 KB)
Hello Alexander,
perfectly works.
Could I anyhow send a matrix into the R Snippet Node too?
I very appreciate your support!
Roland
Hi Roland,
you can pass in anything as long as you can encode it as a string somehow. Maybe it makes sense to encode the matrix as JSON and then decode it in R again.
Kind regards,
Alexander
I do not have too many experience in R.
I tried to write the decoding script, but it was unsuccessful.
Could you help with the decoding of the JSON object?
Please find attached the KNIME model.
Roland
LP_Solve_simple_problem.knwf (43.0 KB)
Meantime I solved this.
I have an other question.
Is it possible to formulate a constraint, which says that the x(i, j) element of the solutions matrix has to be 0(zero)?
Thanks for your help!
Roland
That is great. Could you share the solution so if people find this thread in the future they might find the solution also. Thanks.
Hello,
please find attached the workflow.
I had an issue, while I tried to use the decoded matrix while solving an LP problem.
I could not make numeric matrix from the decoded JSON.
@mlauber71, could you have a look at the attached workflow?
What do I do wrong (bottom R Snippet Node, name with JSON)?
Thanks in advance!
Best Regards
Roland
LP_Solve_simple_problem.knwf (44.9 KB)
Meantime, I solved that too.
Here is the solution code:
library(ājsonliteā)
library(ālpSolveā)
specifying cost matrix
cost.mat <- fromJSON(knime.flow.in[[āJSONā]])
cost.mat <- sapply(cost.mat, FUN=as.numeric)
cost.mat
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.