Change User in R Source Code

Hello everybody,

i´m looking for an solution and hope that somebody can help me.

With KNIME i´m retriving data from our system. The code knows which R-libraries are needed. In this syntax line stands the windows user as not changegable text.
Now what i want to have is, that before running the R-Source KNIME picks up the actual windows user and replace it as needed.

I got the actual User information by using the ‘Extract Context properties’. But now i´m stocking in the replacement step.

The first lines of the R Source Code are looking like this:
library(RODBC, data.table, lib.loc=“C:/Users/lozano/R/win-library/3.3”)
library(data.table, lib.loc=“C:/Users/loano/R/win-library/3.3”)

If somebody else from my team use this workflow i don´t want, that they first have to adjust the parameters for a correct data download. By using the ‘Extract Context properties’-Node it should happen automaticly.

Any suggestions how to solve this?

Best regards
Christopher Lozano

Hi there Christopher,

After Extract Context Properties node use String Manipulation (Variable) node and create new flow variable(s) that you will use in your R Source node. In using String Manipulation (Variable) node there is join() function which you can use.

If you need example I can make one :wink:


Hi @ipazin,

at first I want to thank you for you answer. But at this moment it doesn´t work in the way i want it to.

Following your suggestion i get this Error from KNIME.
ERROR R Source (Table) 0:631 Execute failed: Error in R code:
Error: :3:62: unexpected symbol
3: library(RODBC, data.table, lib.loc="C:/Users/[["WindowsUser

I hope that you can see in the attatched screenshot what i want to do.

After “/User/…” i want that the Workflow automatically write down the current Windows User.

I would apreciate if you can help me by doing an example.

Best regards,

Hi there @Christopher_Lozano,

R node doesn’t perform automatic string join. Instead you should use String Manipulation (Variable) node to create complete lib.loc path.

Here is workflow attached. Check it out. Hope it will help.
2019_06_14_Dynamic_Path_Creation.knwf (8.5 KB)


1 Like

Thanks @ipazin

Your solution worked for me.

1 Like

Glad it helped :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.