How I finally got R working in KNIME on Windows 10

Hi everyone, a few months back I struggled to get R working with KNIME, and in the end gave up, but on getting myself a new laptop I thought I’d try again… And with a fair amount of effort I finally succeeded!

In the hope it may save someone else some time, below are the steps that worked for me. I’d also like to say the following topic really helped me along the way:
Install R alongside KNIME on Windows and MacOS

Steps:

  1. Install R. This is available from www.r-project.org and as of Apr 2020 the latest version was 3.6.3
  2. Install RStudio. This may not strictly be necessary, but it is a superb IDE, as is available from https://rstudio.com
  3. Install Rtools. Rtools is typically used to build your own R packages, but it is also needed to install the latest Rserve package, which itself is needed to run R in KNIME.
  1. Install the Rserve package.
  • Open R or RStudio and in the console type:
    install.packages(‘Rserve’,‘http://rforge.net/',type='source’)
  • This will then install the Rserve package into your User Library. If you do not know where this is type .libPaths() or in RStudio go to: Tools | Install Packages… You will then find the user directory in the Install to Library drop-down
  • Once installed, check you have the latest version - as of Apr 2020 KNIME needed 1.8.6 - by typing into the console:
    packageVersion(“Rserve”)
  • KNIME only seems to recognises Rserve if it is loaded into the System library, usually located in “C:\Program Files\R\R-3.6.3\library”, so copy the Rserve folder from your User Library folder, and place it here
  1. Open up KNIME and install the “KNIME Interactive R Statistics Integration” extension through File | Install KNIME Extensions…
  • Once installed, go to File | Preferences | KNIME | R and you’ll be asked to point it to RHome. RHome is likely to be located in a folder similar to:
    C:\Program Files\R\R-3.6.3

Using R in KNIME:

It became immediately clear to me that there’s a number of different ways you could use R in KNIME, from pretty much building workflows solely using R nodes, to having discreet sections of the workflow using R, to just having the odd R Snippet node amongst an otherwise standard KNIME workflow. The attached R_Intro_1.knar gives very basic examples of some of these.

R_Intro_1.knar (30.4 KB)

I hope this will be of help. Now it’s time for me to actually make the most of it!!!

10 Likes

Thank you for sharing this information.

It would be nice if KNIME became more flexible as regards the location of the R packages. Right now, it really appears to force you to install any R packages into the system directory, which requires that you have read-write access to the library folder in the program directory. This is not convenient (e.g. when you update to a new R version -> you have to copy all the packages to the new location) and may also pose security threats (given the read-write access to the aforementioned folder).

1 Like

Slight correction to my previous post: you can force KNIME to read the packages in the R_USER_LIB folder. However, Rserve requires to be installed in the R system library directory. This may be an Rserve issue …

1 Like

Script provided by @Mark_Ortmann works perfectly on MAC -

3 Likes

Here is link to the R Installation Guide with script location:
https://docs.knime.com/latest/r_installation_guide/index.html

1 Like

The script works well for MacOS. I found two things I had to change/remember

On Windows you would have to install a new version of RTools in oder to get R 4.0 up and ruinning
https://cran.r-project.org/bin/windows/Rtools/

3 Likes

@mlauber71 ,
thx for you prompt feedback and help!

We slightly adjusted the script in the meanwhile and you are now asked to provide the R version you want to install (if you don’t want to install 3.6.1).
We’ll also add the chmod u+x command to the doc :slight_smile:.

Best
Mark

4 Likes

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