How to use multiple install libraries

I have ggplot2 installed in a personal user library.  When I try to use a node and require(ggplot2) I get the following error:

Execution of R script failed: Error in library(ggplot2) : there is no package called 'ggplot2'

However, when I run require(ggplot2) from within R studio, it runs fine.

In my Knime preferences> R>Path to R Home... I am pointing to my personal R install C:\Program Files\R\R-3.2.1

The ggplot2 package is installed in a library that is in My Documents\R\win-library\3.2

My .libPaths() in R points to both the My Documents and the Program Files R libraries so I think that is why it works.

> .libPaths()
[1] "C:/Users/davida/Documents/R/win-library/3.2" "C:/Program Files/R/R-3.2.1/library"        

How do I get Knime to recognize both libraries?

 

Thanks

 

Hi,

I will answer with a question. Why don't you copy the R libraries you have in

  my documents  

in your

  "C:/Program Files/R/R-3.2.1/library"   ?

You can see more details here : http://tech.knime.org/forum/knime-general/loading-r-libraries-in-2104

Best regards

Fabien

I am not sure whether what follows is an elegant solution but it currently works for me.

From the R FAQ:

"2.15 How do I set environment variables?

Environment variables can be set for Rgui.exe and Rterm.exe in three different ways.

[...]

​3. For all applications via Windows. How you set an environment variable is system-specific: under recent versions of Windows, go to ‘User Accounts’ in the Control Panel, and select your account and then ‘Change my environment variables’."

In other words, just set a new environment variable: R_LIBS = "C:\Program Files\R\R-3.2.1\library\". Setting this variable on your Windows system will allow R (e.g. via RStudio or itself) to install or update any packages within the specified folder instead of the My Documents folder. This way, you do not have to worry about copying any updated packages and you can work normally with R outside of KNIME (if so required). No need to manage multiple folders or copies of packages either.

However, beware when you install any major update to the R application itself which triggers a folder name changes - don't forget to update the R_LIB environment variable as well.

EDIT: depending on the Windows configuration, this solution should work without admin rights.