Q:

R dynamically import library

I'm trying to create a function that will either load a library if it exists, or try to install it if it does not.  Where I am stuck is how to dynamically use the library function.  R makes this hard because the library function doesn't only accept a string. 
For instance, to load h2o:
library('h2o') ## This works
library(h2o) ## This also works...

But what if I have a variable named h2o? 
h2o <- 'plyr'
library(h2o) ## imports the h2o package, not plyr

How can I use a variable to dynamically load a package? 

A:

Use the character.only=TRUE option for your library call.   See ? library:
h20 <- "plyr";
library(h20, character.only=TRUE);

sessionInfo();

