[R] is library loaded

Duncan Murdoch murdoch at stats.uwo.ca
Tue Sep 13 22:00:11 CEST 2005


On 9/13/2005 3:09 PM, Omar Lakkis wrote:
> Is there a way to test if a library has been loaded?
> 
> is.loaded does not give me what I want, I am looking to say:
> 
> if loaded(Rdbi) dbSendQuery(conn, q)
> if loaded(RODBC) sqlQuery(conn, q)
> 
> I need this to support both unix and windows platforms as I could not
> find a windows distribution for RdbiPgSQL. I am using R 2.1.0 and
> postgresql. I will be connecting to the database using Rdbi and
> RdbiPgSQL and have other developers using windows connect with RODBC,
> unless someone can suggest a better solution.

You can use the strangely named "require" function, as in

if (require(Rdbi)) dbSendQuery(conn, q)
else if (require(RODBC) sqlQuery(conn, q)
else stop("Nothing works")

Duncan Murdoch




More information about the R-help mailing list