Help in using flow variables in R snippet

Hi guys,

I'm using the R snippet node present in the KNIME Labs – R (Interactive). As I'm new using flow variables, I need your help to do something that is easy in theory: use the value of a flow variable in the R snippet as a variable name.

I will explain it better. I have the following working R snippet code:,

which builds a linear model using the variable “housecost” as response,and which is present in the data. Now I want to generalize it and I want to pass to the model the response variable name (in this case “housecost”) using a flow variable called “response” which value is “housecost”.

I tried the following:[["response"]]~.,

but it gave me the error:

Error in model.frame.default(formula =[["response"]] ~ ., :

variable lengths differ (found for 'X')



I also tried:


But it gave me a similar error.

I'm sure I'm missing something obvious, but I cannot understand from basic documentation. Please, can you help me to understand?


My guess (!) is that the problem might stem from the formula mode in lm() - AFAIR, it would expect the variable name without "". Maybe there is an alternative way of formulating lm()? e.g. as.formula() allows you to construct a formula expression with quoted strings, which would then look like lm(as.formula(paste0([["response"]], " ~ .")), data = Not sure whether that works...

Another possibility is to use the flow variable in Knime to change the name of the responsevar to a generic name just before handing the data set to the R node.