how to source an R script in R view node

Hi all,

This question might have been asked but I couldn't find by searching "how to source an R script in KNIME".

I would like to source two R scripts in my R code written in R view node.

How can I do it? Because in R workscape it doesn't allow me to source the scripts.

Thanks for your help in advance.

Canan

Hi Canan,

I am not entierly sure, what you mean, so I will provide some possible answers and hope one of them fits:

If you want to use the R script in a different R environment, you can save (or more fitting would be "export") a script to a file by using Ctrl+S in the node dialog. You should then be able to load that script into your R workspace. Be aware, that other R environments do not provide the "knime.in" variable for example. You can, of course, just copy&paste the script.

It should be possible to use the source() function in the R nodes without problems for including other R scripts from files or connections.

If this is just for running the entire R script at once, there is the "Evaluate Script" button in the node dialog. Running the R node should probably be kind of similar to sourcing the contained script in most other R editors aswell (It does not write the script to disk, though).

I hope some of that helped, otherwise, try asking differently in case I misunderstood what you are trying to do.

Regards, Jonathan.

When you are using a type of R block, you can source a file in your knime.workspace by using the regular "source" command, referring to your workspace:

source(paste(knime.flow.in[["knime.workspace"]],"/MyWorkflowName/MyRFile.R",sep=""))

This will work fine as long as you're referring only to scripts in the current workflow, and your workflow name does not change. Be warned that when using KNIME Server you will not be able to execute scripts in other workflows -- the workspace becomes a temporary workspace which contains only the current workflow. (I have not yet figured out a good workaround to refer to shared scripts across workflows -- it will probably require using an absolute path).